bridgetown-view-component 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 98cf1967e206477d3d79b8e951abc7523557fd8bb6b20c7f8938d5e35de6497e
4
+ data.tar.gz: 502ef348097c8ca6b2db755c4193a0aaa756fd6b46713436d8b2973ed905402e
5
+ SHA512:
6
+ metadata.gz: 1f7388410c8bb94a61d4ddac9683e325952148357495fddc372ef9c2357df36ee79b4f8164a9ed4a96331602bc2c30c4f995fbd4722cae98631d122e81fe0ab2
7
+ data.tar.gz: c6ec5a0959364ab81292a84181a3a9860c933f1015da8779b24bb8a7996a7c52ff8881048121632e34afe9edb7441933c2012a698796960e8ab876f46f124ed2
data/.gitignore ADDED
@@ -0,0 +1,38 @@
1
+ /vendor
2
+ /.bundle/
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+ *.bundle
12
+ *.so
13
+ *.o
14
+ *.a
15
+ mkmf.log
16
+ *.gem
17
+ Gemfile.lock
18
+ .bundle
19
+ .ruby-version
20
+
21
+ # Node
22
+ node_modules
23
+ .npm
24
+ .node_repl_history
25
+
26
+ # Yarn
27
+ yarn-error.log
28
+ yarn-debug.log*
29
+ .pnp/
30
+ .pnp.js
31
+
32
+ # Yarn Integrity file
33
+ .yarn-integrity
34
+
35
+ spec/dest
36
+ .bridgetown-metadata
37
+ .bridgetown-cache
38
+ .bridgetown-webpack
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.rubocop.yml ADDED
@@ -0,0 +1,22 @@
1
+ require: rubocop-bridgetown
2
+
3
+ inherit_gem:
4
+ rubocop-bridgetown: .rubocop.yml
5
+
6
+ AllCops:
7
+ TargetRubyVersion: 2.5
8
+ Include:
9
+ - lib/**/*.rb
10
+
11
+ Exclude:
12
+ - .gitignore
13
+ - .rspec
14
+ - .rubocop.yml
15
+
16
+ - Gemfile.lock
17
+ - CHANGELOG.md
18
+ - LICENSE.txt
19
+ - README.md
20
+
21
+ - script/**/*
22
+ - vendor/**/*
data/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # main
2
+
3
+ * Use this file to keep track of plugin updates
4
+
5
+ # 0.1.0 / 2020-05-01
6
+
7
+ * First version
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+ gemspec
5
+
6
+ gem "bridgetown", ENV["BRIDGETOWN_VERSION"] if ENV["BRIDGETOWN_VERSION"]
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020-present
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,14 @@
1
+ # ViewComponent for Bridgetown
2
+
3
+ Bridgetown + ViewComponent = :heart:
4
+
5
+ WIP — stay tuned!
6
+
7
+ ## Contributing
8
+
9
+ 1. Fork it (https://github.com/bridgetownrb/bridgetown-view-component/fork)
10
+ 2. Clone the fork using `git clone` to your local development machine.
11
+ 3. Create your feature branch (`git checkout -b my-new-feature`)
12
+ 4. Commit your changes (`git commit -am 'Add some feature'`)
13
+ 5. Push to the branch (`git push origin my-new-feature`)
14
+ 6. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task :default => :spec
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/bridgetown-view-component/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "bridgetown-view-component"
7
+ spec.version = Bridgetown::ViewComponent::VERSION
8
+ spec.author = "Bridgetown Team"
9
+ spec.email = "maintainers@bridgetownrb.com"
10
+ spec.summary = "Brings GitHub's ViewComponent library to Bridgetown"
11
+ spec.homepage = "https://github.com/bridgetownrb/bridgetown-view-component"
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r!^(test|script|spec|features|frontend)/!) }
15
+ spec.test_files = spec.files.grep(%r!^spec/!)
16
+ spec.require_paths = ["lib"]
17
+
18
+ spec.required_ruby_version = ">= 2.5.0"
19
+
20
+ spec.add_dependency "bridgetown", ">= 0.21.0.beta1", "< 2.0"
21
+ spec.add_dependency "view_component", ">= 2.20"
22
+ spec.add_dependency "actionview", "~> 6.0"
23
+
24
+ spec.add_development_dependency "bundler"
25
+ spec.add_development_dependency "nokogiri", "~> 1.6"
26
+ spec.add_development_dependency "rake", "~> 12.0"
27
+ spec.add_development_dependency "rspec", "~> 3.0"
28
+ spec.add_development_dependency "rubocop-bridgetown", "~> 0.2"
29
+ end
@@ -0,0 +1 @@
1
+ Hello <%= @name %>! Welcome to Bridgetown + ViewComponent. 😃
@@ -0,0 +1,11 @@
1
+ module Bridgetown
2
+ module ViewComponent
3
+ class SanityCheckComponent < ::ViewComponent::Base
4
+ include Bridgetown::ViewComponent
5
+
6
+ def initialize(name:)
7
+ @name = name
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bridgetown-core"
4
+ require "action_view"
5
+ require "view_component"
6
+
7
+ # Create basic Rails namespace when in Bridgetown-only context
8
+ unless defined?(Rails)
9
+ module Rails
10
+ module UrlHelpers; end
11
+
12
+ def self.version
13
+ ActionView.version.to_s
14
+ end
15
+
16
+ def self.application
17
+ @application ||= HashWithDotAccess::Hash.new({
18
+ routes: { url_helpers: UrlHelpers },
19
+ })
20
+ end
21
+
22
+ def self.env
23
+ @env ||= HashWithDotAccess::Hash.new({ production?: Bridgetown.env.production? })
24
+ end
25
+ end
26
+
27
+ unless Rails.version.to_f >= 6.1
28
+ require "view_component/render_monkey_patch"
29
+ ActionView::Base.prepend ViewComponent::RenderMonkeyPatch
30
+ end
31
+ end
32
+
33
+ # Load classes/modules
34
+
35
+ module Bridgetown
36
+ module ViewComponent
37
+ end
38
+
39
+ autoload :ViewComponentHelpers,
40
+ "bridgetown-view-component/bridgetown/view_component_helpers"
41
+ autoload :ComponentValidation,
42
+ "bridgetown-view-component/bridgetown/component_validation"
43
+ end
44
+
45
+ # Set up the test components source manifest
46
+ Bridgetown::PluginManager.new_source_manifest(
47
+ origin: Bridgetown::ViewComponent,
48
+ components: File.expand_path("../components", __dir__)
49
+ )
50
+
51
+ # Add a few methods to Bridgetown's Ruby template superclasses
52
+ [Bridgetown::RubyTemplateView, Bridgetown::Component].each do |klass|
53
+ klass.class_eval do
54
+ def lookup_context
55
+ HashWithDotAccess::Hash.new(variants: [])
56
+ end
57
+
58
+ def view_renderer
59
+ nil
60
+ end
61
+
62
+ def view_flow
63
+ nil
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bridgetown
4
+ module ComponentValidation
5
+ def self.included(klass)
6
+ klass.attr_reader :frontmatter
7
+ end
8
+
9
+ def frontmatter=(yaml_data)
10
+ @frontmatter = yaml_data.with_dot_access
11
+
12
+ frontmatter.validate&.each do |variable, type|
13
+ unless send(variable).is_a?(Kernel.const_get(type))
14
+ raise "Validation error while rendering #{self.class}: " \
15
+ "`#{variable}' is not of type `#{type}'"
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bridgetown
4
+ module ViewComponentARCHIVED
5
+ # NOTE: Currently not in use...might need to revisit when dual Rails/Bridgetown
6
+ # installs are present
7
+ def self.setup_hooks
8
+ Bridgetown::Hooks.register :site, :pre_render, reloadable: false do
9
+ ::ViewComponent::CompileCache.cache.each do |component_class|
10
+ component_class.undef_method(:call)
11
+ end
12
+ ::ViewComponent::CompileCache.cache.clear
13
+ end
14
+
15
+ Bridgetown::Hooks.register :site, :post_render, reloadable: false do |_post|
16
+ ::ViewComponent::CompileCache.cache.each do |component_class|
17
+ component_class.undef_method(:call)
18
+ end
19
+ ::ViewComponent::CompileCache.cache.clear
20
+ end
21
+ end
22
+
23
+ def self.included(klass)
24
+ klass.extend ClassMethods
25
+ end
26
+
27
+ module ClassMethods
28
+ def content_format(type)
29
+ @content_format = type
30
+ end
31
+
32
+ def format_for_content
33
+ @content_format ||= :default
34
+ end
35
+ end
36
+
37
+ def content
38
+ if self.class.format_for_content == :markdown && view_context.respond_to?(:markdownify)
39
+ view_context.markdownify(@content).html_safe
40
+ else
41
+ super
42
+ end
43
+ end
44
+
45
+ def render_in(view_context, &block)
46
+ if view_context.class.name&.start_with? "Bridgetown"
47
+ singleton_class.include ViewComponentHelpers
48
+ end
49
+
50
+ super
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bridgetown
4
+ module ViewComponentHelpers
5
+ extend Forwardable
6
+
7
+ def_delegators :@view_context, :liquid_render, :partial
8
+
9
+ attr_reader :site # will be nil unless you explicitly set a `@site` ivar
10
+
11
+ def self.helper_allow_list
12
+ @helper_allow_list ||= %i(capture render t with_output_buffer)
13
+ end
14
+
15
+ def self.allow_rails_helpers(*helpers)
16
+ helper_allow_list.concat(helpers)
17
+ end
18
+
19
+ def self.included(klass)
20
+ helper_consts = ActionView::Helpers.constants.select do |c|
21
+ ActionView::Helpers.const_get(c).is_a?(Module)
22
+ end
23
+ helper_consts.map { |c| ActionView::Helpers.const_get(c) }.each do |mod|
24
+ (mod.public_instance_methods - Object.public_instance_methods).each do |method_name|
25
+ klass.undef_method(method_name) unless helper_allow_list.include?(method_name)
26
+ rescue NameError
27
+ nil
28
+ end
29
+ end
30
+ end
31
+
32
+ def render(item, options = {}, &block)
33
+ if item.respond_to?(:render_in)
34
+ result = ""
35
+ capture do # this ensures no leaky interactions between BT<=>VC blocks
36
+ result = item.render_in(self, &block)
37
+ end
38
+ result&.html_safe
39
+ else
40
+ view_context.partial(item, options, &block)&.html_safe
41
+ end
42
+ end
43
+
44
+ def helpers
45
+ @helpers ||= Bridgetown::RubyTemplateView::Helpers.new(self, @view_context.site)
46
+ end
47
+
48
+ def method_missing(method, *args, &block)
49
+ if helpers.respond_to?(method.to_sym)
50
+ helpers.send method.to_sym, *args, &block
51
+ else
52
+ super
53
+ end
54
+ end
55
+
56
+ def respond_to_missing?(method, include_private = false)
57
+ helpers.respond_to?(method.to_sym, include_private) || super
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.join(
4
+ File.expand_path("../../", __dir__),
5
+ "components",
6
+ "bridgetown",
7
+ "view_component",
8
+ "sanity_check_component"
9
+ )
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bridgetown
4
+ module ViewComponent
5
+ VERSION = "0.6.0"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,177 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bridgetown-view-component
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.0
5
+ platform: ruby
6
+ authors:
7
+ - Bridgetown Team
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-04-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bridgetown
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.21.0.beta1
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '2.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 0.21.0.beta1
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '2.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: view_component
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '2.20'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '2.20'
47
+ - !ruby/object:Gem::Dependency
48
+ name: actionview
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '6.0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '6.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: bundler
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: nokogiri
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '1.6'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '1.6'
89
+ - !ruby/object:Gem::Dependency
90
+ name: rake
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '12.0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '12.0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: rspec
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '3.0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '3.0'
117
+ - !ruby/object:Gem::Dependency
118
+ name: rubocop-bridgetown
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: '0.2'
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: '0.2'
131
+ description:
132
+ email: maintainers@bridgetownrb.com
133
+ executables: []
134
+ extensions: []
135
+ extra_rdoc_files: []
136
+ files:
137
+ - ".gitignore"
138
+ - ".rspec"
139
+ - ".rubocop.yml"
140
+ - CHANGELOG.md
141
+ - Gemfile
142
+ - LICENSE.txt
143
+ - README.md
144
+ - Rakefile
145
+ - bridgetown-view-component.gemspec
146
+ - components/bridgetown/view_component/sanity_check_component.erb
147
+ - components/bridgetown/view_component/sanity_check_component.rb
148
+ - lib/bridgetown-view-component.rb
149
+ - lib/bridgetown-view-component/bridgetown/component_validation.rb
150
+ - lib/bridgetown-view-component/bridgetown/view_component.rb
151
+ - lib/bridgetown-view-component/bridgetown/view_component_helpers.rb
152
+ - lib/bridgetown-view-component/components.rb
153
+ - lib/bridgetown-view-component/version.rb
154
+ homepage: https://github.com/bridgetownrb/bridgetown-view-component
155
+ licenses:
156
+ - MIT
157
+ metadata: {}
158
+ post_install_message:
159
+ rdoc_options: []
160
+ require_paths:
161
+ - lib
162
+ required_ruby_version: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: 2.5.0
167
+ required_rubygems_version: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - ">="
170
+ - !ruby/object:Gem::Version
171
+ version: '0'
172
+ requirements: []
173
+ rubygems_version: 3.1.4
174
+ signing_key:
175
+ specification_version: 4
176
+ summary: Brings GitHub's ViewComponent library to Bridgetown
177
+ test_files: []