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/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 441349a..6bbc46e 100644 --- a/lib/imprint.rb +++ b/lib/imprint.rb @@ -4,6 +4,7 @@ require 'imprint/signer' require 'imprint/renderer' require 'imprint/engine' if defined?(Rails) +require 'imprint/railtie' if defined?(Rails) module Imprint def self.sign(source:, watermark:, expires_in:) diff --git a/lib/imprint/rails/helper.rb b/lib/imprint/rails/helper.rb new file mode 100644 index 0000000..78c0a52 --- /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, **) + image_tag( + imprint_render_path(token: token), + ** + ) + end + end + end +end diff --git a/lib/imprint/railtie.rb b/lib/imprint/railtie.rb new file mode 100644 index 0000000..8f2ff9b --- /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