Skip to content

Commit 11958d2

Browse files
authored
Merge pull request #4 from ggerman/feature/railtie
Feature/railtie
2 parents 095c626 + 3d1cf7f commit 11958d2

6 files changed

Lines changed: 85 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
## [Unreleased]
1+
## Changelog.md
22

3-
## [0.1.0] - 2026-01-20
43

5-
- Initial release
4+
## 0.1.1
5+
- Rails integration documentation
6+
- Optional Railtie for Rails environments
7+
## [0.1.0] - 2026-01-20

README.md

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,45 @@ brew install gd
1818
### Gemfile
1919
```bash
2020
gem 'imprint'
21-
```
21+
```
22+
23+
24+
25+
## Rails integration
26+
27+
Imprint is framework-agnostic, but integrates cleanly with Rails.
28+
29+
### Routes
30+
31+
Define your own route:
32+
33+
```ruby
34+
# config/routes.rb
35+
get '/imprint/:token', to: 'imprint#show'
36+
```
37+
### Controller
38+
39+
```ruby
40+
class ImprintController < ApplicationController
41+
def show
42+
path = Imprint.render_from_token(params[:token])
43+
44+
return head :not_found unless path
45+
46+
send_file path, type: 'image/png', disposition: 'inline'
47+
end
48+
end
49+
```
50+
51+
### Usage
52+
53+
```ruby
54+
token = Imprint.sign(
55+
source: '/path/to/image.png',
56+
watermark: 'CONFIDENTIAL',
57+
expires_in: 5.minutes
58+
)
59+
```
60+
```html
61+
<img src="/imprint/<%= token.split('/').last %>" />
62+
```

imprint.gemspec

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ Gem::Specification.new do |spec|
1010

1111
spec.summary = "Signed, expiring image watermark rendering for Ruby"
1212
spec.description = <<~DESC
13-
Imprint is a Ruby library for generating signed, time-limited image renders
14-
with dynamic text watermarks. It allows you to securely distribute images
15-
using expiring tokens, preventing unauthorized reuse or hotlinking.
13+
Imprint is a Ruby library for generating signed, time-limited image renders
14+
with dynamic text watermarks. It allows you to securely distribute images
15+
using expiring tokens, preventing unauthorized reuse or hotlinking.
1616
17-
Imprint works as a pure Ruby library and can optionally integrate with Rails
18-
via an isolated engine. Image rendering is powered by the GD graphics library.
19-
DESC
17+
Imprint works as a pure Ruby library and can optionally integrate with Rails
18+
via an isolated engine. Image rendering is powered by the GD graphics library.
19+
DESC
2020
spec.homepage = "https://github.com/ggerman/imprint"
2121
spec.license = "MIT"
2222
spec.required_ruby_version = '>= 3.3.0'

lib/imprint.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
require 'imprint/signer'
55
require 'imprint/renderer'
66
require 'imprint/engine' if defined?(Rails)
7+
require 'imprint/railtie' if defined?(Rails)
78

89
module Imprint
910
def self.sign(source:, watermark:, expires_in:)

lib/imprint/rails/helper.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# frozen_string_literal: true
2+
3+
module Imprint
4+
module Rails
5+
module Helper
6+
def imprint_image_tag(token, **)
7+
image_tag(
8+
imprint_render_path(token: token),
9+
**
10+
)
11+
end
12+
end
13+
end
14+
end

lib/imprint/railtie.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# frozen_string_literal: true
2+
3+
require 'rails/railtie'
4+
5+
module Imprint
6+
class Railtie < Rails::Railtie
7+
initializer 'imprint.helpers' do
8+
ActiveSupport.on_load(:action_view) do
9+
include Imprint::Rails::Helper
10+
end
11+
end
12+
13+
initializer 'imprint.configure' do
14+
# Punto de extensión futuro
15+
end
16+
end
17+
end

0 commit comments

Comments
 (0)