opengraphplus 0.1.5 → 0.1.6

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: 7d947ee47bc0e434395f69cceb99321f78ab4f8ac437f5b537b97ffa9a199d51
4
- data.tar.gz: 308d3466e160b11f935afd3b9f0c891ba3b268f95f3de12400af9e815020a82f
3
+ metadata.gz: e8fd514b98d00901b6c41cf42ad246f71690c7fb632c2653f1e66571da1c0968
4
+ data.tar.gz: cb7eef25110066ade4cf4b5f05fe5f10448c7e3cf8a9f6d5bb91b785f7687d37
5
5
  SHA512:
6
- metadata.gz: ac3f345867d3cc9e5ad6fa1745f5f6ea45cf505fdd057191c0af0d48ca62d8af6e64aa7dfa26b2097f8d97af95fab8dec9888a37b00a573bc94c5ad68660c6c3
7
- data.tar.gz: 9a20a378f2e36d594667c2abdba8e194bdcae2bc55a2daf33bf1195162b9c9498ca257e426e645ae85a3087cc0f80b83ff9f7065f730cc240564daf7617e58e7
6
+ metadata.gz: 2f0bb3269f68f0b57ab02e9f583042bae211f5c2f0ca7dec28a7cd35fed2e9e32ac934241380ce856f88a9919dfb2b4bdc8bbc46d2a87d70a2c6694207913a6e
7
+ data.tar.gz: 0b77487f2356101b48750cb729f9b88327678aafabe02fa5da16dc9ea55f2c0d5e5a3a3351ddb1294af14d791e7495fa2012ea82b4cac4afadc90f6d8e4b8770
data/README.md CHANGED
@@ -18,7 +18,55 @@ gem install opengraphplus
18
18
 
19
19
  ## Usage
20
20
 
21
- When this gem is complete, an API key will be required to connect to the gem, the it's installed, added to a layout, and it should just work.
21
+ ### Get your API key
22
+
23
+ Sign up at [og.plus](https://og.plus) to get your API key.
24
+
25
+ ### Configuration
26
+
27
+ #### Using environment variables
28
+
29
+ ```bash
30
+ rails g opengraphplus:env ogp_live_████████████████████
31
+ ```
32
+
33
+ This will:
34
+ - Append `OPENGRAPHPLUS__API_KEY=ogp_live_████████████████████` to your `.env` file (or the first env file found)
35
+ - Create `config/initializers/opengraphplus.rb`
36
+
37
+ To specify a different env file:
38
+
39
+ ```bash
40
+ rails g opengraphplus:env ogp_live_████████████████████ -e .envrc
41
+ ```
42
+
43
+ #### Using Rails credentials
44
+
45
+ ```bash
46
+ rails g opengraphplus:credentials ogp_live_████████████████████
47
+ ```
48
+
49
+ This will:
50
+ - Add `opengraphplus.api_key` to your encrypted `credentials.yml.enc`
51
+ - Create `config/initializers/opengraphplus.rb`
52
+
53
+ #### Manual configuration
54
+
55
+ Run the basic install generator for a commented template:
56
+
57
+ ```bash
58
+ rails g opengraphplus:install
59
+ ```
60
+
61
+ Then configure manually in `config/initializers/opengraphplus.rb`:
62
+
63
+ ```ruby
64
+ OpenGraphPlus.configure do |config|
65
+ config.api_key = ENV["OPENGRAPHPLUS__API_KEY"]
66
+ # or
67
+ config.api_key = Rails.application.credentials.opengraphplus.api_key
68
+ end
69
+ ```
22
70
 
23
71
  ## Development
24
72
 
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/generators"
4
+
5
+ module Opengraphplus
6
+ module Generators
7
+ class BaseGenerator < Rails::Generators::Base
8
+ API_KEY_PREFIX = "ogp_"
9
+
10
+ argument :api_key, type: :string, required: true,
11
+ desc: "Your OpenGraphPlus API key"
12
+
13
+ def validate_api_key
14
+ unless api_key.start_with?(API_KEY_PREFIX)
15
+ say_status :error, "Invalid API key: must start with '#{API_KEY_PREFIX}'", :red
16
+ raise SystemExit
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "yaml"
4
+ require "active_support/core_ext/hash/keys"
5
+ require_relative "../base_generator"
6
+
7
+ module Opengraphplus
8
+ module Generators
9
+ class CredentialsGenerator < BaseGenerator
10
+ source_root File.expand_path("templates", __dir__)
11
+
12
+ desc "Configures OpenGraphPlus using Rails encrypted credentials"
13
+
14
+ def add_to_credentials
15
+ credentials = Rails.application.credentials
16
+
17
+ unless credentials.key?
18
+ say_status :error, "No credentials key found. Run `rails credentials:edit` first.", :red
19
+ return
20
+ end
21
+
22
+ # Read existing content, merge, write back
23
+ yaml_content = credentials.read.presence || ""
24
+ config = parse_yaml(yaml_content)
25
+
26
+ config["opengraphplus"] ||= {}
27
+ config["opengraphplus"]["api_key"] = api_key
28
+
29
+ credentials.write(yaml_dump(config))
30
+ say_status :insert, "credentials.yml.enc (opengraphplus.api_key)", :green
31
+ end
32
+
33
+ def create_initializer
34
+ template "initializer.rb.tt", "config/initializers/opengraphplus.rb"
35
+ end
36
+
37
+ private
38
+
39
+ def parse_yaml(content)
40
+ return {} if content.blank?
41
+ YAML.safe_load(content, permitted_classes: [Symbol], aliases: true) || {}
42
+ end
43
+
44
+ def yaml_dump(config)
45
+ # Preserve nice formatting
46
+ YAML.dump(config.deep_stringify_keys)
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ OpenGraphPlus.configure do |config|
4
+ config.api_key = Rails.application.credentials.opengraphplus.api_key
5
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../base_generator"
4
+
5
+ module Opengraphplus
6
+ module Generators
7
+ class EnvGenerator < BaseGenerator
8
+ source_root File.expand_path("templates", __dir__)
9
+
10
+ desc "Configures OpenGraphPlus using environment variables"
11
+
12
+ class_option :envfile, type: :string, aliases: "-e",
13
+ desc: "Specific env file to write to (e.g., .env, .envrc)"
14
+
15
+ ENV_FILES = %w[.env .env.local .env.development .env.development.local .envrc].freeze
16
+ ENV_VAR_NAME = "OPENGRAPHPLUS__API_KEY"
17
+
18
+ def append_to_env_file
19
+ if options[:envfile]
20
+ write_to_env_file(options[:envfile], create: true)
21
+ else
22
+ env_file = detect_env_file
23
+ if env_file
24
+ write_to_env_file(env_file)
25
+ else
26
+ say_status :skip, "No env file found (create one or use -e)", :yellow
27
+ end
28
+ end
29
+ end
30
+
31
+ def create_initializer
32
+ template "initializer.rb.tt", "config/initializers/opengraphplus.rb"
33
+ end
34
+
35
+ private
36
+
37
+ def detect_env_file
38
+ ENV_FILES.find { |f| File.exist?(f) }
39
+ end
40
+
41
+ def write_to_env_file(env_file, create: false)
42
+ env_line = "#{ENV_VAR_NAME}=#{api_key}"
43
+
44
+ unless File.exist?(env_file)
45
+ if create
46
+ create_file env_file, "#{env_line}\n"
47
+ end
48
+ return
49
+ end
50
+
51
+ if File.read(env_file).include?(ENV_VAR_NAME)
52
+ say_status :skip, "#{env_file} (#{ENV_VAR_NAME} already defined)", :yellow
53
+ else
54
+ content = File.read(env_file)
55
+ prefix = content.end_with?("\n") || content.empty? ? "" : "\n"
56
+ append_to_file env_file, "#{prefix}#{env_line}\n"
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ OpenGraphPlus.configure do |config|
4
+ config.api_key = ENV["OPENGRAPHPLUS__API_KEY"]
5
+ end
@@ -1,46 +1,6 @@
1
1
 
2
2
  OpenGraphPlus has been installed!
3
3
 
4
- Next steps:
5
-
6
- 1. Add your API key to config/initializers/opengraphplus.rb
7
- Get your API key at: https://opengraphplus.com/dashboard
8
-
9
- 2. Add the helper to your layout file (e.g., app/views/layouts/application.html.erb):
10
-
11
- <head>
12
- <%%= open_graph_meta_tags %>
13
- </head>
14
-
15
- 3. Customize the default Open Graph tags in ApplicationController:
16
-
17
- class ApplicationController < ActionController::Base
18
- open_graph do |og|
19
- og.type = "website"
20
- og.url = request.original_url
21
- og.site_name = "Your Site Name"
22
- end
23
- end
24
-
25
- 4. Override tags in specific controllers (inherits from parent):
26
-
27
- class ArticlesController < ApplicationController
28
- before_action { @article = Article.find(params[:id]) }
29
-
30
- open_graph do |og|
31
- og.title = @article.title
32
- og.description = @article.excerpt
33
- og.type = "article"
34
- end
35
- end
36
-
37
- 5. Set tags in views:
38
-
39
- <%% open_graph do |og|
40
- og.title = "My Page Title"
41
- og.description = "My Page Description"
42
- end %>
43
-
44
- 6. Verify it works by checking your page source for og:image meta tags,
45
- or use the preview tool at: https://opengraphplus.com/previews/new
4
+ For setup instructions, visit https://opengraphplus.com/guides/rails
46
5
 
6
+ For a website API key, visit https://opengraphplus.com/dashboard
@@ -1,8 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Get your API key at https://opengraphplus.com/dashboard
3
4
  OpenGraphPlus.configure do |config|
4
- # Get your API key at https://opengraphplus.com/dashboard
5
+ # Use Rails credentials.
5
6
  config.api_key = Rails.application.credentials.opengraphplus_api_key
7
+
6
8
  # Or use ENV:
7
9
  # config.api_key = ENV["OPENGRAPHPLUS_API_KEY"]
8
10
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OpenGraphPlus
4
- VERSION = "0.1.5"
4
+ VERSION = "0.1.6"
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opengraphplus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brad Gessler
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2026-01-07 00:00:00.000000000 Z
10
+ date: 2026-01-08 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: activesupport
@@ -34,6 +34,11 @@ files:
34
34
  - LICENSE.txt
35
35
  - README.md
36
36
  - Rakefile
37
+ - lib/generators/opengraphplus/base_generator.rb
38
+ - lib/generators/opengraphplus/credentials/credentials_generator.rb
39
+ - lib/generators/opengraphplus/credentials/templates/initializer.rb.tt
40
+ - lib/generators/opengraphplus/env/env_generator.rb
41
+ - lib/generators/opengraphplus/env/templates/initializer.rb.tt
37
42
  - lib/generators/opengraphplus/install/install_generator.rb
38
43
  - lib/generators/opengraphplus/install/templates/README
39
44
  - lib/generators/opengraphplus/install/templates/initializer.rb