bridgetown_jam_comments 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4cec102f903d67ff5d30fef92aa7748089ade11a2cb67b4177fe2c06795b24e9
4
+ data.tar.gz: 6e0eb8bdc6c859ba4981dff3c450629d41b3328d0cb1fad8f9e7e7e209b09287
5
+ SHA512:
6
+ metadata.gz: 6a456e51630ba2a33de9c84ab904aaa859d67f678846f5ffd9039489cf7d8927c7fec3e096f3dbd8c0fe94358da0e08d6021f5d70e1a08b3c80bbcbb8b12c1e8
7
+ data.tar.gz: 015f7f3d5f64d24b3e044acf82364a4672e97f8f840280850d2661e964c0d321979192406109a9b20b8c900b788408fc0b381c12ac02a6fb2e49dafd1917f6bf
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Alex MacArthur
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # bridgetown-jam-comments
2
+
3
+ A Ruby gem for setting up your [Bridgetown](https://www.bridgetownrb.com/) blog with [JamComments](https://jamcomments.com), a guilt-free commment service for Jamstack blogs.
4
+
5
+ ## This Package's Documentation
6
+
7
+ ...coming soon!
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "./service"
4
+ require_relative "./renderer"
5
+ require_relative "./configuration"
6
+
7
+ module JamComments
8
+ class Builder < Bridgetown::Builder
9
+ def build
10
+ liquid_tag :jam_comments, :render
11
+ end
12
+
13
+ private
14
+
15
+ def render(attributes, tag)
16
+ Renderer.new(config.bridgetown_jam_comments).render(attributes, tag)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JamComments
4
+ class Configuration
5
+ attr_reader :config
6
+
7
+ def initialize(config)
8
+ @config = config
9
+ end
10
+
11
+ def domain
12
+ config["domain"] || ENV.fetch("JAM_COMMENTS_DOMAIN", nil)
13
+ end
14
+
15
+ def base_url
16
+ config["base_url"] || ENV.fetch("JAM_COMMENTS_BASE_URL", nil)
17
+ end
18
+
19
+ def api_key
20
+ config["api_key"] || ENV.fetch("JAM_COMMENTS_API_KEY", nil)
21
+ end
22
+
23
+ def environment
24
+ config["environment"] || ENV["JAM_COMMENTS_ENVIRONMENT"] || ENV.fetch("BRIDGETOWN_ENV", nil)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pry"
4
+
5
+ module JamComments
6
+ class Renderer
7
+ CLIENT_SCRIPT_URL = "https://unpkg.com/@jam-comments/client@2.0.0-beta.2/dist/index.umd.js"
8
+
9
+ attr_reader :provided_configuration
10
+
11
+ def initialize(provided_configuration)
12
+ @provided_configuration = provided_configuration
13
+ end
14
+
15
+ def render(_attributes, tag)
16
+ context = tag.context
17
+ path = context["page"] && context["page"]["relative_url"]
18
+ markup = service.fetch(path: path)
19
+
20
+ "
21
+ #{markup}
22
+ <script src=\"#{CLIENT_SCRIPT_URL}\"></script>
23
+ <script>
24
+ window.JamComments.initialize();
25
+ </script>
26
+ "
27
+ end
28
+
29
+ private
30
+
31
+ def configuration
32
+ @configuration ||= Configuration.new(provided_configuration)
33
+ end
34
+
35
+ def service
36
+ @service ||= Service.new(
37
+ domain: configuration.domain,
38
+ api_key: configuration.api_key,
39
+ base_url: configuration.base_url,
40
+ environment: configuration.environment
41
+ )
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "httparty"
4
+
5
+ module JamComments
6
+ class Service
7
+ attr_reader :base_url, :environment, :domain, :api_key, :client
8
+
9
+ def initialize(
10
+ domain:,
11
+ api_key:,
12
+ base_url: nil,
13
+ environment: nil,
14
+ client: HTTParty
15
+ )
16
+ @client = client
17
+ @domain = domain
18
+ @api_key = api_key
19
+ @base_url = base_url || "https://go.jamcomments.com"
20
+ @environment = environment || "production"
21
+ end
22
+
23
+ def fetch(path:)
24
+ options = {
25
+ query: {
26
+ path: formatted_path(path),
27
+ domain: domain,
28
+ stub: stub_value,
29
+ },
30
+ headers: {
31
+ Authorization: "Bearer #{api_key}",
32
+ Accept: "application/json",
33
+ "X-Platform": "jekyll",
34
+ },
35
+ }
36
+
37
+ send_request(options)
38
+ end
39
+
40
+ private
41
+
42
+ def send_request(options)
43
+ response = client.get(endpoint, options)
44
+
45
+ raise "Oh no! It looks like your credentials for JamComments are incorrect." if response.code == 401
46
+
47
+ raise "Oh no! JamComments request failed. Please try again. Status: #{response.code}" if response.code != 200
48
+
49
+ response.body
50
+ end
51
+
52
+ def stub_value
53
+ return "true" if environment != "production"
54
+
55
+ nil
56
+ end
57
+
58
+ def endpoint
59
+ "#{base_url}/api/v2/markup"
60
+ end
61
+
62
+ def formatted_path(path)
63
+ path.empty? ? "/" : path
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JamComments
4
+ VERSION = "0.0.1"
5
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bridgetown"
4
+ require_relative "./bridgetown_jam_comments/builder"
5
+
6
+ Bridgetown.initializer :bridgetown_jam_comments do |config, domain: nil, api_key: nil, base_url: nil, environment: nil|
7
+ config.bridgetown_jam_comments ||= {}
8
+ config.bridgetown_jam_comments[:domain] = config.bridgetown_jam_comments.domain || domain
9
+ config.bridgetown_jam_comments[:api_key] = config.bridgetown_jam_comments.api_key || api_key
10
+ config.bridgetown_jam_comments[:base_url] = config.bridgetown_jam_comments.base_url || base_url
11
+ config.bridgetown_jam_comments[:environment] =
12
+ config.bridgetown_jam_comments.environment || environment
13
+
14
+ config.builder JamComments::Builder
15
+ end
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bridgetown_jam_comments
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Alex MacArthur
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-04-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bridgetown
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop-bridgetown
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description:
112
+ email:
113
+ - alex@macarthur.me
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files:
117
+ - README.md
118
+ - LICENSE.txt
119
+ files:
120
+ - LICENSE.txt
121
+ - README.md
122
+ - lib/bridgetown_jam_comments.rb
123
+ - lib/bridgetown_jam_comments/builder.rb
124
+ - lib/bridgetown_jam_comments/configuration.rb
125
+ - lib/bridgetown_jam_comments/renderer.rb
126
+ - lib/bridgetown_jam_comments/service.rb
127
+ - lib/bridgetown_jam_comments/version.rb
128
+ homepage: https://github.com/alexmacarthur/bridgetown-jam-comments
129
+ licenses:
130
+ - MIT
131
+ metadata: {}
132
+ post_install_message:
133
+ rdoc_options: []
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: 2.7.2
141
+ required_rubygems_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ requirements: []
147
+ rubygems_version: 3.1.4
148
+ signing_key:
149
+ specification_version: 4
150
+ summary: A Bridgetown plugin for setting up JamComments in a Bridgetown site.
151
+ test_files: []