From 0a7781176facc1bc1cf6fecbb10853c886bf6dcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gim=C3=A9nez=20Silva=20Germ=C3=A9n=20Alberto?= Date: Wed, 21 Jan 2026 08:42:14 -0300 Subject: [PATCH 1/6] Add optional Rails integration and documentation --- CHANGELOG.md | 8 +++++--- README.md | 43 +++++++++++++++++++++++++++++++++++++++++- lib/imprint.rb | 4 ++++ lib/imprint/railtie.rb | 17 +++++++++++++++++ 4 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 lib/imprint/railtie.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index 153c040..4c978eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ -## [Unreleased] +## Changelog.md -## [0.1.0] - 2026-01-20 -- Initial release +## 0.1.1 +- Rails integration documentation +- Optional Railtie for Rails environments +## [0.1.0] - 2026-01-20 \ No newline at end of file diff --git a/README.md b/README.md index 32ca37d..3e40e9a 100644 --- a/README.md +++ b/README.md @@ -18,4 +18,45 @@ brew install gd ### Gemfile ```bash gem 'imprint' -``` \ No newline at end of file +``` + + + +## Rails integration + +Imprint is framework-agnostic, but integrates cleanly with Rails. + +### Routes + +Define your own route: + +```ruby +# config/routes.rb +get '/imprint/:token', to: 'imprint#show' +``` +### Controller + +```ruby +class ImprintController < ApplicationController + def show + path = Imprint.render_from_token(params[:token]) + + return head :not_found unless path + + send_file path, type: 'image/png', disposition: 'inline' + end +end +``` + +### Usage + +```ruby +token = Imprint.sign( + source: '/path/to/image.png', + watermark: 'CONFIDENTIAL', + expires_in: 5.minutes +) +``` +```html + +``` diff --git a/lib/imprint.rb b/lib/imprint.rb index 441349a..7236e33 100644 --- a/lib/imprint.rb +++ b/lib/imprint.rb @@ -5,6 +5,10 @@ require 'imprint/renderer' require 'imprint/engine' if defined?(Rails) +if defined?(Rails) + require 'imprint/railtie' +end + module Imprint def self.sign(source:, watermark:, expires_in:) payload = { diff --git a/lib/imprint/railtie.rb b/lib/imprint/railtie.rb new file mode 100644 index 0000000..fd80895 --- /dev/null +++ b/lib/imprint/railtie.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +require 'rails/railtie' + +module Imprint + class Railtie < Rails::Railtie + initializer 'imprint.helpers' do + ActiveSupport.on_load(:action_view) do + include Imprint::Rails::Helper + end + end + + initializer 'imprint.configure' do + # Punto de extensión futuro + end + end +end From 113f154c3db1cc867cecf9b3dd4b651d1b35fa45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gim=C3=A9nez=20Silva=20Germ=C3=A9n=20Alberto?= Date: Wed, 21 Jan 2026 08:43:11 -0300 Subject: [PATCH 2/6] adding helper --- lib/imprint/rails/helper.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 lib/imprint/rails/helper.rb diff --git a/lib/imprint/rails/helper.rb b/lib/imprint/rails/helper.rb new file mode 100644 index 0000000..b7b46fd --- /dev/null +++ b/lib/imprint/rails/helper.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +module Imprint + module Rails + module Helper + def imprint_image_tag(token, **options) + image_tag( + imprint_render_path(token: token), + **options + ) + end + end + end +end From 1871483f7b5a41d30f445c6da946a1e45ff08ebe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gim=C3=A9nez=20Silva=20Germ=C3=A9n=20Alberto?= Date: Wed, 21 Jan 2026 08:46:16 -0300 Subject: [PATCH 3/6] update commit to pass Rubocop --- imprint.gemspec | 12 ++++++------ lib/imprint.rb | 5 +---- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/imprint.gemspec b/imprint.gemspec index 26e4455..b789f1e 100644 --- a/imprint.gemspec +++ b/imprint.gemspec @@ -10,13 +10,13 @@ Gem::Specification.new do |spec| spec.summary = "Signed, expiring image watermark rendering for Ruby" spec.description = <<~DESC - Imprint is a Ruby library for generating signed, time-limited image renders - with dynamic text watermarks. It allows you to securely distribute images - using expiring tokens, preventing unauthorized reuse or hotlinking. + Imprint is a Ruby library for generating signed, time-limited image renders + with dynamic text watermarks. It allows you to securely distribute images + using expiring tokens, preventing unauthorized reuse or hotlinking. - Imprint works as a pure Ruby library and can optionally integrate with Rails - via an isolated engine. Image rendering is powered by the GD graphics library. -DESC + Imprint works as a pure Ruby library and can optionally integrate with Rails + via an isolated engine. Image rendering is powered by the GD graphics library. + DESC spec.homepage = "https://github.com/ggerman/imprint" spec.license = "MIT" spec.required_ruby_version = '>= 3.3.0' diff --git a/lib/imprint.rb b/lib/imprint.rb index 7236e33..6bbc46e 100644 --- a/lib/imprint.rb +++ b/lib/imprint.rb @@ -4,10 +4,7 @@ require 'imprint/signer' require 'imprint/renderer' require 'imprint/engine' if defined?(Rails) - -if defined?(Rails) - require 'imprint/railtie' -end +require 'imprint/railtie' if defined?(Rails) module Imprint def self.sign(source:, watermark:, expires_in:) From 5172af52df7a37e744791bfc61ddbaf5f3ac8505 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gim=C3=A9nez=20Silva=20Germ=C3=A9n=20Alberto?= Date: Wed, 21 Jan 2026 08:50:33 -0300 Subject: [PATCH 4/6] Fix RuboCop keyword forwarding and indentation --- lib/imprint/rails/helper.rb | 8 ++++---- lib/imprint/railtie.rb | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/imprint/rails/helper.rb b/lib/imprint/rails/helper.rb index b7b46fd..549dac6 100644 --- a/lib/imprint/rails/helper.rb +++ b/lib/imprint/rails/helper.rb @@ -3,12 +3,12 @@ module Imprint module Rails module Helper - def imprint_image_tag(token, **options) + def imprint_image_tag(token, **) image_tag( - imprint_render_path(token: token), - **options + imprint_render_path(token: token), + ** ) - end + end end end end diff --git a/lib/imprint/railtie.rb b/lib/imprint/railtie.rb index fd80895..8f2ff9b 100644 --- a/lib/imprint/railtie.rb +++ b/lib/imprint/railtie.rb @@ -5,9 +5,9 @@ module Imprint class Railtie < Rails::Railtie initializer 'imprint.helpers' do - ActiveSupport.on_load(:action_view) do - include Imprint::Rails::Helper - end + ActiveSupport.on_load(:action_view) do + include Imprint::Rails::Helper + end end initializer 'imprint.configure' do From 9af01cba46981290d5bd3ee4e7327d9a2e347b7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gim=C3=A9nez=20Silva=20Germ=C3=A9n=20Alberto?= Date: Wed, 21 Jan 2026 08:52:04 -0300 Subject: [PATCH 5/6] fixing indentation --- lib/imprint/rails/helper.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/imprint/rails/helper.rb b/lib/imprint/rails/helper.rb index 549dac6..7e97eda 100644 --- a/lib/imprint/rails/helper.rb +++ b/lib/imprint/rails/helper.rb @@ -4,10 +4,10 @@ module Imprint module Rails module Helper def imprint_image_tag(token, **) - image_tag( - imprint_render_path(token: token), - ** - ) + image_tag( + imprint_render_path(token: token), + ** + ) end end end From 3d1cf7f45a8dbd6d51ab44a06f04a1031fc6893d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gim=C3=A9nez=20Silva=20Germ=C3=A9n=20Alberto?= Date: Wed, 21 Jan 2026 08:59:51 -0300 Subject: [PATCH 6/6] Fix Rails helper indentation for RuboCop --- lib/imprint/rails/helper.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/imprint/rails/helper.rb b/lib/imprint/rails/helper.rb index 7e97eda..78c0a52 100644 --- a/lib/imprint/rails/helper.rb +++ b/lib/imprint/rails/helper.rb @@ -3,12 +3,12 @@ module Imprint module Rails module Helper - def imprint_image_tag(token, **) - image_tag( - imprint_render_path(token: token), - ** - ) - end + def imprint_image_tag(token, **) + image_tag( + imprint_render_path(token: token), + ** + ) + end end end end