imageomatic 0.1.1 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7903eeab14e261a76042cba4e2a2127dc84bf4d1bb1c88d3cec3b2e8fddafa87
4
- data.tar.gz: 336a739324d3dc2216e9089bebff9e1a47f513cc3049906a3b036d4a73529ab9
3
+ metadata.gz: 56c3cad53d8ab41c03d1062ff85f3d0616680c1703a57592d33a92878921e485
4
+ data.tar.gz: 787aef08807389181b223c5f9a27b41af680954425d80afd9b767699963590f6
5
5
  SHA512:
6
- metadata.gz: e47c991db4e2d284a28853ab375864dc6d8a5cf12743c629694045ad7be2c822362797ebc3bc7afa15189c5154c7d98d68dc3f9ad4b97002781248e8134d0da5
7
- data.tar.gz: 91a59cce1f7a876d4fec576c6f7560e043ff0ac996308370abad4403fe392594383a869bf77506bb19d37b5818451522565efded925a9d774a457879756fa6f1
6
+ metadata.gz: 0addd92d5d109f408285aa777d9234a69652472a9a5cb0e12809baa9a15b5565c04640458f2acd879897b125df544586a37cfed6571c5cf711e4d3fb04f2455a
7
+ data.tar.gz: b3047ca8ec7f5394bd1e8a4c4b15fd281a17cb6b9ff9630dc38aaa53a06ff9629682a86de45141365d86a560b1dda41e2a8292bac8306548c6e7944a9d589060
@@ -2,6 +2,9 @@ module Imageomatic
2
2
  module Opengraph
3
3
  extend ActiveSupport::Concern
4
4
 
5
+ DEFAULT_OPENGRAPH_TYPE = "website".freeze
6
+
7
+ DEFAULT_OPENGRAPH_FALLBACK_FORMATS = [ :opengraph, :html ]
5
8
  included do
6
9
  before_action :assign_opengraph_fallback_formats, if: :opengraph_request?
7
10
  before_action :assign_opengraph_defaults
@@ -13,7 +16,7 @@ module Imageomatic
13
16
 
14
17
  protected
15
18
  def assign_opengraph_fallback_formats
16
- request.formats = [ :opengraph, :html ]
19
+ request.formats = DEFAULT_OPENGRAPH_FALLBACK_FORMATS
17
20
  end
18
21
 
19
22
  def opengraph_request?
@@ -21,7 +24,7 @@ module Imageomatic
21
24
  end
22
25
 
23
26
  def url_for_opengraph_image
24
- url_for(format: :opengraph)
27
+ Imageomatic.client.url_signature.url_for "opengraph", url: url_for(format: :opengraph)
25
28
  end
26
29
 
27
30
  def opengraph
@@ -30,6 +33,7 @@ module Imageomatic
30
33
 
31
34
  def assign_opengraph_defaults
32
35
  opengraph.image ||= url_for_opengraph_image
36
+ opengraph.type ||= DEFAULT_OPENGRAPH_TYPE
33
37
  end
34
38
  end
35
39
  end
@@ -1,6 +1,6 @@
1
1
  module Imageomatic
2
2
  module Opengraph
3
- class Model < Struct.new(:title, :image, :description)
3
+ class Model < Struct.new(:title, :image, :description, :type)
4
4
  include ActionView::Helpers::OutputSafetyHelper
5
5
 
6
6
  def metatags
data/exe/imageomatic ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require "imageomatic"
3
+
4
+ Imageomatic::CLI.start ARGV
@@ -12,4 +12,8 @@ class Imageomatic::InstallGenerator < Rails::Generators::Base
12
12
  def copy_layout
13
13
  copy_file "application.opengraph.erb", "app/views/layouts/application.opengraph.erb"
14
14
  end
15
+
16
+ def copy_configuration_file
17
+ template "imageomatic.rb.tt", "config/initializers/imageomatic.rb"
18
+ end
15
19
  end
@@ -0,0 +1,14 @@
1
+ Imageomatic.configure do |config|
2
+ if Rails.env.production?
3
+ # For production deployments, set the following environment keys:
4
+ #
5
+ # ```
6
+ # IMAGEOMATIC_SECRET_KEY=
7
+ # IMAGEOMATIC_PUBLIC_KEY=
8
+ # ```
9
+ config.load_env
10
+ else
11
+ config.secret_key = "<%= Imageomatic.key_generator.secret_key %>"
12
+ config.public_key = "<%= Imageomatic.key_generator.public_key %>"
13
+ end
14
+ end
@@ -0,0 +1,23 @@
1
+ require "thor"
2
+
3
+ module Imageomatic
4
+ class CLI < Thor
5
+ include Thor::Actions
6
+
7
+ desc "install", "Install Imageomatic to the Rails application"
8
+ def install
9
+ run "./bin/bundle add imageomatic"
10
+ run "./bin/rails generate imageomatic:install"
11
+ end
12
+
13
+ desc "version", "Prints the version of imageomatic"
14
+ def version
15
+ puts Imageomatic::VERSION
16
+ end
17
+
18
+ desc "environment [ENVIRONMENT]", "Generates environment variables for target enrivonment"
19
+ def environment(environment = Imageomatic::KeyGenerator::ENVIRONMENT)
20
+ puts Imageomatic.key_generator(environment: environment).env_vars
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,13 @@
1
+ module Imageomatic
2
+ class Client
3
+ delegate :secret_key, :public_key, to: :configuration
4
+
5
+ def url_signature
6
+ @url_signature ||= UrlSignature.new(secret_key: secret_key, public_key: public_key)
7
+ end
8
+
9
+ def configuration
10
+ @configuration ||= Configuration.new
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,18 @@
1
+ module Imageomatic
2
+ class Configuration
3
+ attr_accessor :secret_key, :public_key
4
+
5
+ def load_secret_key_env
6
+ self.secret_key = ENV.fetch("IMAGEOMATIC_SECRET_KEY")
7
+ end
8
+
9
+ def load_public_key_env
10
+ self.public_key = ENV.fetch("IMAGEOMATIC_PUBLIC_KEY")
11
+ end
12
+
13
+ def load_env
14
+ load_secret_key_env
15
+ load_public_key_env
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,43 @@
1
+ require "securerandom"
2
+
3
+ module Imageomatic
4
+ # Generates random keys for environments.
5
+ class KeyGenerator
6
+ LENGTH = 14
7
+ DELIMITER = "_".freeze
8
+ ENVIRONMENT = :development
9
+
10
+ attr_reader :environment
11
+
12
+ def initialize(environment: ENVIRONMENT)
13
+ @environment = environment
14
+ end
15
+
16
+ def public_key
17
+ generate :public
18
+ end
19
+
20
+ def secret_key
21
+ generate :secret
22
+ end
23
+
24
+ def env_vars
25
+ <<~ENVARS
26
+ IMAGEOMATIC_SECRET_KEY=#{secret_key}
27
+ IMAGEOMATIC_PUBLIC_KEY=#{public_key}
28
+ ENVARS
29
+ end
30
+
31
+ def generate(*scopes)
32
+ scopes
33
+ .prepend(environment)
34
+ .append(random)
35
+ .join(DELIMITER)
36
+ end
37
+
38
+ private
39
+ def random
40
+ SecureRandom.hex(LENGTH)
41
+ end
42
+ end
43
+ end
@@ -1,3 +1,3 @@
1
1
  module Imageomatic
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/lib/imageomatic.rb CHANGED
@@ -1,6 +1,24 @@
1
1
  require "imageomatic/version"
2
- require "imageomatic/engine"
2
+ require "imageomatic/engine" if defined? Rails
3
3
 
4
4
  module Imageomatic
5
- autoload :UrlSignature, "imageomatic/url_signature"
5
+ autoload :CLI, "imageomatic/cli"
6
+ autoload :Client, "imageomatic/client"
7
+ autoload :Configuration, "imageomatic/configuration"
8
+ autoload :KeyGenerator, "imageomatic/key_generator"
9
+ autoload :UrlSignature, "imageomatic/url_signature"
10
+
11
+ class << self
12
+ def client
13
+ @client ||= Client.new
14
+ end
15
+
16
+ def key_generator(environment: Rails.env)
17
+ @key_generator ||= KeyGenerator.new(environment: environment)
18
+ end
19
+
20
+ def configure(&block)
21
+ block.call client.configuration
22
+ end
23
+ end
6
24
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imageomatic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brad Gessler
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2022-06-17 00:00:00.000000000 Z
11
+ date: 2022-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -24,10 +24,25 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 7.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.0.0
27
41
  description: Easiest way to generate fresh images for Rails applications.
28
42
  email:
29
43
  - brad@imageomatic.com
30
- executables: []
44
+ executables:
45
+ - imageomatic
31
46
  extensions: []
32
47
  extra_rdoc_files: []
33
48
  files:
@@ -48,11 +63,17 @@ files:
48
63
  - app/views/layouts/imageomatic/application.html.erb
49
64
  - config/initializers/mime_types.rb
50
65
  - config/routes.rb
66
+ - exe/imageomatic
51
67
  - lib/generators/imageomatic/install/USAGE
52
68
  - lib/generators/imageomatic/install/install_generator.rb
53
69
  - lib/generators/imageomatic/install/templates/application.opengraph.erb
70
+ - lib/generators/imageomatic/install/templates/imageomatic.rb.tt
54
71
  - lib/imageomatic.rb
72
+ - lib/imageomatic/cli.rb
73
+ - lib/imageomatic/client.rb
74
+ - lib/imageomatic/configuration.rb
55
75
  - lib/imageomatic/engine.rb
76
+ - lib/imageomatic/key_generator.rb
56
77
  - lib/imageomatic/url_signature.rb
57
78
  - lib/imageomatic/version.rb
58
79
  - lib/tasks/imageomatic_tasks.rake