imageomatic 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +98 -0
- data/Rakefile +8 -0
- data/app/assets/config/imageomatic_manifest.js +1 -0
- data/app/assets/stylesheets/imageomatic/application.css +15 -0
- data/app/controllers/concerns/imageomatic/opengraph.rb +35 -0
- data/app/controllers/imageomatic/application_controller.rb +4 -0
- data/app/helpers/imageomatic/application_helper.rb +4 -0
- data/app/helpers/imageomatic/opengraph_tag_helper.rb +7 -0
- data/app/jobs/imageomatic/application_job.rb +4 -0
- data/app/mailers/imageomatic/application_mailer.rb +6 -0
- data/app/models/imageomatic/application_record.rb +5 -0
- data/app/models/imageomatic/opengraph/metatag.rb +11 -0
- data/app/models/imageomatic/opengraph/model.rb +19 -0
- data/app/views/layouts/imageomatic/application.html.erb +15 -0
- data/config/initializers/mime_types.rb +3 -0
- data/config/routes.rb +2 -0
- data/lib/generators/imageomatic/install/USAGE +11 -0
- data/lib/generators/imageomatic/install/install_generator.rb +15 -0
- data/lib/generators/imageomatic/install/templates/application.opengraph.erb +15 -0
- data/lib/imageomatic/engine.rb +5 -0
- data/lib/imageomatic/version.rb +3 -0
- data/lib/imageomatic.rb +6 -0
- data/lib/tasks/imageomatic_tasks.rake +4 -0
- metadata +85 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5f21da146260850a58131cbc1beff664ba283c6677e954c66da84e89d2674a8f
|
4
|
+
data.tar.gz: 50c93f247027c69cc997d04cf06c8b6f96df98f0abd14f86aa40e577e66c80b5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 00060a525441bf8c6621073e1dc101d90dee901aa53951c992630ad3756d65afc84564285294f4734f9afa6b96182f1cd8226eb4fc24cc856dc43afa2f47b74e
|
7
|
+
data.tar.gz: 1a1047e9e4bc9e443f3ee55507f2639530c414fb08d04f15829a0783bcebf74c1e4d79a3af0a75efa23b3aa3ca53d5a19e52a1f8f98ec68238be07ea35d47f1c
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2022 Brad Gessler
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
# Imageomatic
|
2
|
+
|
3
|
+
[](https://github.com/imageomatic/ruby/actions/workflows/ruby.yml)
|
4
|
+
|
5
|
+
The easiest way to make Rails applications look great in Apple Messages, Facebook, LinkedIn, Twitter, and any other website that use Open Graph.
|
6
|
+
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
From the root of your Rails application, run:
|
11
|
+
|
12
|
+
```bash
|
13
|
+
$ bundle add "imageomatic"
|
14
|
+
```
|
15
|
+
|
16
|
+
Then run:
|
17
|
+
|
18
|
+
```bash
|
19
|
+
$ rails generate install:imageomatic
|
20
|
+
```
|
21
|
+
|
22
|
+
This creates a `app/views/layout/application.opengraph.erb` file and adds `include Imageomatic::Opengraph` to `ApplicationController`.
|
23
|
+
|
24
|
+
Add to your `app/views/layouts/application.html.erb` file:
|
25
|
+
|
26
|
+
```
|
27
|
+
<head>
|
28
|
+
<%= opengraph_meta_tags %>
|
29
|
+
</head>
|
30
|
+
```
|
31
|
+
|
32
|
+
That's it for the bare minimum! A screenshot of the top part of the webpage will appear by default for all open graph images. Custom badges are where its at though, so read on my friend.
|
33
|
+
|
34
|
+
## Setting OpenGraph data
|
35
|
+
|
36
|
+
Open graph data can be set from the view or controller via the `opengraph` method.
|
37
|
+
|
38
|
+
### Controller
|
39
|
+
|
40
|
+
Here's a few ways to set opengraph data from a controller.
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
class PostsController < ApplicationController
|
44
|
+
before_action: :assign_opengraph_data
|
45
|
+
|
46
|
+
def edit
|
47
|
+
# This overrides the title that's set from `assign_opengraph_data`
|
48
|
+
opengraph.title = "Editing #{@post.title}"
|
49
|
+
end
|
50
|
+
|
51
|
+
protected
|
52
|
+
|
53
|
+
def assign_opengraph_data
|
54
|
+
opengraph.title = @post.title
|
55
|
+
opengraph.description = @post.summary
|
56
|
+
# Displays the first image of a blog post, instead of a screenshot, for the opengraph image.
|
57
|
+
# Assumes the image was managed via ActiveStorage.
|
58
|
+
opengraph.image = url_for(@post.images.first)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
```
|
62
|
+
|
63
|
+
### View
|
64
|
+
|
65
|
+
Opengraph data may also be set from the view:
|
66
|
+
|
67
|
+
```erb
|
68
|
+
<%
|
69
|
+
opengraph.title = @post.title
|
70
|
+
opengraph.description = @post.summary
|
71
|
+
%>
|
72
|
+
|
73
|
+
<h1><%= @post.title %></h1>
|
74
|
+
<article><%= @post.body %></article>
|
75
|
+
```
|
76
|
+
|
77
|
+
## Custom badges with Rails Views
|
78
|
+
|
79
|
+
The real power in Imageomatic Open Graph is creating custom badges via the `opengraph` format in your rails views. For the example below, we'll create an Open Graph badge for a blog post. Assuming a blog application has a `/posts/:id` with a view at `app/views/posts/show.html.erb`, we'd create a new view with the `opengraph` format:
|
80
|
+
|
81
|
+
```bash
|
82
|
+
$ touch ./app/views/posts/show.opengraph.erb
|
83
|
+
```
|
84
|
+
|
85
|
+
Open the file and add something like:
|
86
|
+
|
87
|
+
```erb
|
88
|
+
|
89
|
+
<h1><%= @post.title %></h1>
|
90
|
+
<article><%= truncate @post.body, length: 100 %></article>
|
91
|
+
<p>This article will take <%= time_to_read @post.body %> minutes to read</p>
|
92
|
+
```
|
93
|
+
|
94
|
+
The Imageomatic screenshot service will take a screenshot of the content at this URL and use it for the Open Graph image.
|
95
|
+
|
96
|
+
## License
|
97
|
+
|
98
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
//= link_directory ../stylesheets/imageomatic .css
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
|
10
|
+
* files in this directory. Styles in this file should be added after the last require_* statement.
|
11
|
+
* It is generally better to create a new file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Imageomatic
|
2
|
+
module Opengraph
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
before_action :assign_opengraph_fallback_formats, if: :opengraph_request?
|
7
|
+
before_action :assign_opengraph_defaults
|
8
|
+
|
9
|
+
helper Imageomatic::OpengraphTagHelper
|
10
|
+
|
11
|
+
helper_method :opengraph
|
12
|
+
end
|
13
|
+
|
14
|
+
protected
|
15
|
+
def assign_opengraph_fallback_formats
|
16
|
+
request.formats = [ :opengraph, :html ]
|
17
|
+
end
|
18
|
+
|
19
|
+
def opengraph_request?
|
20
|
+
request.format.opengraph?
|
21
|
+
end
|
22
|
+
|
23
|
+
def url_for_opengraph_image
|
24
|
+
url_for(format: :opengraph)
|
25
|
+
end
|
26
|
+
|
27
|
+
def opengraph
|
28
|
+
@opengraph ||= Model.new
|
29
|
+
end
|
30
|
+
|
31
|
+
def assign_opengraph_defaults
|
32
|
+
opengraph.image ||= url_for_opengraph_image
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Imageomatic
|
2
|
+
module Opengraph
|
3
|
+
class Model < Struct.new(:title, :image, :description)
|
4
|
+
include ActionView::Helpers::OutputSafetyHelper
|
5
|
+
|
6
|
+
def metatags
|
7
|
+
Enumerator.new do |y|
|
8
|
+
each_pair do |property, content|
|
9
|
+
y << Metatag.new(property, content) if content.present?
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_html
|
15
|
+
safe_join metatags.map(&:to_html), "\n"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/config/routes.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
class Imageomatic::InstallGenerator < Rails::Generators::Base
|
2
|
+
source_root File.expand_path("templates", __dir__)
|
3
|
+
|
4
|
+
def include_controller_helper
|
5
|
+
inject_into_file 'app/controllers/application_controller.rb', after: "class ApplicationController < ActionController::Base\n" do <<-'RUBY'
|
6
|
+
include Imageomatic::Opengraph
|
7
|
+
|
8
|
+
RUBY
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def copy_layout
|
13
|
+
copy_file "application.opengraph.erb", "app/views/layouts/application.opengraph.erb"
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title><%= opengraph.title %></title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<%= csrf_meta_tags %>
|
7
|
+
<%= csp_meta_tag %>
|
8
|
+
|
9
|
+
<%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
|
10
|
+
<%= javascript_importmap_tags %>
|
11
|
+
</head>
|
12
|
+
<body>
|
13
|
+
<%= yield %>
|
14
|
+
</body>
|
15
|
+
</html>
|
data/lib/imageomatic.rb
ADDED
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: imageomatic
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brad Gessler
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-06-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 7.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 7.0.0
|
27
|
+
description: Easiest way to generate fresh images for Rails applications.
|
28
|
+
email:
|
29
|
+
- brad@imageomatic.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- MIT-LICENSE
|
35
|
+
- README.md
|
36
|
+
- Rakefile
|
37
|
+
- app/assets/config/imageomatic_manifest.js
|
38
|
+
- app/assets/stylesheets/imageomatic/application.css
|
39
|
+
- app/controllers/concerns/imageomatic/opengraph.rb
|
40
|
+
- app/controllers/imageomatic/application_controller.rb
|
41
|
+
- app/helpers/imageomatic/application_helper.rb
|
42
|
+
- app/helpers/imageomatic/opengraph_tag_helper.rb
|
43
|
+
- app/jobs/imageomatic/application_job.rb
|
44
|
+
- app/mailers/imageomatic/application_mailer.rb
|
45
|
+
- app/models/imageomatic/application_record.rb
|
46
|
+
- app/models/imageomatic/opengraph/metatag.rb
|
47
|
+
- app/models/imageomatic/opengraph/model.rb
|
48
|
+
- app/views/layouts/imageomatic/application.html.erb
|
49
|
+
- config/initializers/mime_types.rb
|
50
|
+
- config/routes.rb
|
51
|
+
- lib/generators/imageomatic/install/USAGE
|
52
|
+
- lib/generators/imageomatic/install/install_generator.rb
|
53
|
+
- lib/generators/imageomatic/install/templates/application.opengraph.erb
|
54
|
+
- lib/imageomatic.rb
|
55
|
+
- lib/imageomatic/engine.rb
|
56
|
+
- lib/imageomatic/version.rb
|
57
|
+
- lib/tasks/imageomatic_tasks.rake
|
58
|
+
homepage: https://www.imageomatic.com/
|
59
|
+
licenses:
|
60
|
+
- MIT
|
61
|
+
metadata:
|
62
|
+
allowed_push_host: https://rubygems.org/
|
63
|
+
homepage_uri: https://www.imageomatic.com/
|
64
|
+
source_code_uri: https://github.com/imageomatic/ruby
|
65
|
+
changelog_uri: https://github.com/imageomatic/ruby/releases
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
requirements: []
|
81
|
+
rubygems_version: 3.3.15
|
82
|
+
signing_key:
|
83
|
+
specification_version: 4
|
84
|
+
summary: Easiest way to generate fresh images for Rails applications.
|
85
|
+
test_files: []
|