bridgetown-core 0.19.2 → 0.21.0.beta3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/bridgetown-core.gemspec +1 -2
  3. data/lib/bridgetown-core.rb +37 -29
  4. data/lib/bridgetown-core/cleaner.rb +9 -3
  5. data/lib/bridgetown-core/collection.rb +177 -78
  6. data/lib/bridgetown-core/commands/base.rb +9 -0
  7. data/lib/bridgetown-core/commands/build.rb +0 -11
  8. data/lib/bridgetown-core/commands/concerns/git_helpers.rb +20 -0
  9. data/lib/bridgetown-core/commands/configure.rb +8 -3
  10. data/lib/bridgetown-core/commands/console.rb +4 -0
  11. data/lib/bridgetown-core/commands/doctor.rb +1 -19
  12. data/lib/bridgetown-core/commands/new.rb +2 -2
  13. data/lib/bridgetown-core/commands/plugins.rb +14 -13
  14. data/lib/bridgetown-core/commands/serve.rb +0 -14
  15. data/lib/bridgetown-core/component.rb +178 -0
  16. data/lib/bridgetown-core/concerns/data_accessible.rb +1 -0
  17. data/lib/bridgetown-core/concerns/front_matter_importer.rb +52 -0
  18. data/lib/bridgetown-core/concerns/site/configurable.rb +10 -10
  19. data/lib/bridgetown-core/concerns/site/content.rb +56 -15
  20. data/lib/bridgetown-core/concerns/site/localizable.rb +3 -5
  21. data/lib/bridgetown-core/concerns/site/processable.rb +6 -4
  22. data/lib/bridgetown-core/concerns/site/renderable.rb +26 -0
  23. data/lib/bridgetown-core/concerns/site/writable.rb +12 -2
  24. data/lib/bridgetown-core/concerns/validatable.rb +2 -5
  25. data/lib/bridgetown-core/configuration.rb +51 -30
  26. data/lib/bridgetown-core/configurations/bt-postcss.rb +1 -3
  27. data/lib/bridgetown-core/configurations/netlify.rb +1 -0
  28. data/lib/bridgetown-core/configurations/tailwindcss.rb +1 -3
  29. data/lib/bridgetown-core/converter.rb +23 -0
  30. data/lib/bridgetown-core/converters/erb_templates.rb +51 -35
  31. data/lib/bridgetown-core/converters/identity.rb +0 -9
  32. data/lib/bridgetown-core/converters/liquid_templates.rb +1 -1
  33. data/lib/bridgetown-core/converters/markdown.rb +14 -4
  34. data/lib/bridgetown-core/converters/markdown/kramdown_parser.rb +5 -38
  35. data/lib/bridgetown-core/converters/ruby_templates.rb +17 -0
  36. data/lib/bridgetown-core/converters/smartypants.rb +3 -1
  37. data/lib/bridgetown-core/core_ext/psych.rb +19 -0
  38. data/lib/bridgetown-core/current.rb +10 -0
  39. data/lib/bridgetown-core/document.rb +9 -16
  40. data/lib/bridgetown-core/drops/collection_drop.rb +1 -1
  41. data/lib/bridgetown-core/drops/page_drop.rb +4 -0
  42. data/lib/bridgetown-core/drops/relations_drop.rb +23 -0
  43. data/lib/bridgetown-core/drops/resource_drop.rb +83 -0
  44. data/lib/bridgetown-core/drops/site_drop.rb +33 -8
  45. data/lib/bridgetown-core/drops/unified_payload_drop.rb +5 -0
  46. data/lib/bridgetown-core/entry_filter.rb +17 -28
  47. data/lib/bridgetown-core/errors.rb +0 -2
  48. data/lib/bridgetown-core/filters.rb +3 -26
  49. data/lib/bridgetown-core/filters/from_liquid.rb +23 -0
  50. data/lib/bridgetown-core/filters/url_filters.rb +12 -0
  51. data/lib/bridgetown-core/frontmatter_defaults.rb +1 -1
  52. data/lib/bridgetown-core/generators/prototype_generator.rb +37 -19
  53. data/lib/bridgetown-core/helpers.rb +48 -9
  54. data/lib/bridgetown-core/layout.rb +28 -13
  55. data/lib/bridgetown-core/liquid_renderer/file.rb +1 -0
  56. data/lib/bridgetown-core/liquid_renderer/table.rb +1 -0
  57. data/lib/bridgetown-core/model/base.rb +138 -0
  58. data/lib/bridgetown-core/model/builder_origin.rb +40 -0
  59. data/lib/bridgetown-core/model/origin.rb +38 -0
  60. data/lib/bridgetown-core/model/repo_origin.rb +126 -0
  61. data/lib/bridgetown-core/page.rb +11 -2
  62. data/lib/bridgetown-core/plugin_manager.rb +1 -3
  63. data/lib/bridgetown-core/publisher.rb +8 -2
  64. data/lib/bridgetown-core/reader.rb +37 -22
  65. data/lib/bridgetown-core/readers/data_reader.rb +5 -5
  66. data/lib/bridgetown-core/readers/defaults_reader.rb +1 -1
  67. data/lib/bridgetown-core/readers/page_reader.rb +1 -0
  68. data/lib/bridgetown-core/readers/post_reader.rb +5 -4
  69. data/lib/bridgetown-core/regenerator.rb +9 -2
  70. data/lib/bridgetown-core/related_posts.rb +9 -6
  71. data/lib/bridgetown-core/renderer.rb +6 -13
  72. data/lib/bridgetown-core/resource/base.rb +313 -0
  73. data/lib/bridgetown-core/resource/destination.rb +49 -0
  74. data/lib/bridgetown-core/resource/permalink_processor.rb +179 -0
  75. data/lib/bridgetown-core/resource/relations.rb +132 -0
  76. data/lib/bridgetown-core/resource/taxonomy_term.rb +34 -0
  77. data/lib/bridgetown-core/resource/taxonomy_type.rb +56 -0
  78. data/lib/bridgetown-core/resource/transformer.rb +177 -0
  79. data/lib/bridgetown-core/ruby_template_view.rb +11 -11
  80. data/lib/bridgetown-core/site.rb +13 -6
  81. data/lib/bridgetown-core/static_file.rb +33 -10
  82. data/lib/bridgetown-core/tags/highlight.rb +2 -15
  83. data/lib/bridgetown-core/tags/include.rb +1 -1
  84. data/lib/bridgetown-core/tags/post_url.rb +2 -2
  85. data/lib/bridgetown-core/url.rb +1 -0
  86. data/lib/bridgetown-core/utils.rb +49 -43
  87. data/lib/bridgetown-core/utils/require_gems.rb +60 -0
  88. data/lib/bridgetown-core/utils/ruby_exec.rb +6 -9
  89. data/lib/bridgetown-core/utils/ruby_front_matter.rb +39 -0
  90. data/lib/bridgetown-core/version.rb +2 -2
  91. data/lib/bridgetown-core/watcher.rb +1 -1
  92. data/lib/bridgetown-core/yaml_parser.rb +22 -0
  93. data/lib/site_template/package.json.erb +2 -2
  94. data/lib/site_template/plugins/site_builder.rb +1 -1
  95. data/lib/site_template/src/_posts/0000-00-00-welcome-to-bridgetown.md.erb +1 -1
  96. data/lib/site_template/webpack.config.js.erb +26 -6
  97. metadata +39 -40
  98. data/lib/bridgetown-core/external.rb +0 -58
  99. data/lib/bridgetown-core/page_without_a_file.rb +0 -17
  100. data/lib/bridgetown-core/path_manager.rb +0 -31
  101. data/lib/bridgetown-core/readers/collection_reader.rb +0 -23
  102. data/lib/bridgetown-core/readers/static_file_reader.rb +0 -25
  103. data/lib/bridgetown-core/utils/exec.rb +0 -26
  104. data/lib/bridgetown-core/utils/internet.rb +0 -37
  105. data/lib/bridgetown-core/utils/platforms.rb +0 -80
  106. data/lib/bridgetown-core/utils/thread_event.rb +0 -31
  107. data/lib/bridgetown-core/utils/win_tz.rb +0 -75
@@ -25,6 +25,15 @@ module Bridgetown
25
25
  end
26
26
  end
27
27
 
28
+ desc "dream", "There's a place where that idea still exists as a reality"
29
+ def dream
30
+ puts ""
31
+ puts "🎶 The Dream of the 90s is Alive in Portland... ✨"
32
+ puts " https://youtu.be/U4hShMEk1Ew"
33
+ puts " https://youtu.be/0_HGqPGp9iY"
34
+ puts ""
35
+ end
36
+
28
37
  desc "help <command>", "Show detailed command usage information and exit"
29
38
  def help(subcommand = nil)
30
39
  if subcommand && respond_to?(subcommand)
@@ -79,17 +79,6 @@ module Bridgetown
79
79
  #
80
80
  # Returns nothing.
81
81
  def watch_site(config_options)
82
- # Warn Windows users that they might need to upgrade.
83
- if Utils::Platforms.bash_on_windows?
84
- Bridgetown.logger.warn "",
85
- "Auto-regeneration may not work on some Windows versions."
86
- Bridgetown.logger.warn "",
87
- "Please see: https://github.com/Microsoft/BashOnWindows/issues/216"
88
- Bridgetown.logger.warn "",
89
- "If it does not work, please upgrade Bash on Windows or "\
90
- "run Bridgetown with --no-watch."
91
- end
92
-
93
82
  Bridgetown::Watcher.watch(@site, config_options)
94
83
  end
95
84
 
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bridgetown
4
+ module Commands
5
+ module GitHelpers
6
+ def initialize_new_repo
7
+ run "git init", abort_on_failure: true
8
+ `git symbolic-ref HEAD refs/heads/main` if user_default_branch.empty?
9
+ end
10
+
11
+ def destroy_existing_repo
12
+ run "rm -rf .git"
13
+ end
14
+
15
+ def user_default_branch
16
+ @user_default_branch ||= `git config init.defaultbranch`.strip
17
+ end
18
+ end
19
+ end
20
+ end
@@ -4,6 +4,7 @@ module Bridgetown
4
4
  module Commands
5
5
  class Configure < Thor::Group
6
6
  include Thor::Actions
7
+ include Actions
7
8
  extend Summarizable
8
9
 
9
10
  Registrations.register do
@@ -20,13 +21,13 @@ module Bridgetown
20
21
  end
21
22
 
22
23
  def perform_configurations
23
- logger = Bridgetown.logger
24
+ @logger = Bridgetown.logger
24
25
  list_configurations if args.empty?
25
26
 
26
27
  args.each do |configuration|
27
28
  configure configuration
28
29
  rescue Thor::Error
29
- logger.error "Error:".red, "🚨 Configuration doesn't exist: #{configuration}"
30
+ @logger.error "Error:".red, "🚨 Configuration doesn't exist: #{configuration}"
30
31
  end
31
32
  end
32
33
 
@@ -40,7 +41,7 @@ module Bridgetown
40
41
  configuration_file = find_in_source_paths("#{configuration}.rb")
41
42
 
42
43
  inside(New.created_site_dir || Dir.pwd) do
43
- Apply.new.invoke(:apply_automation, [configuration_file])
44
+ apply configuration_file, verbose: false
44
45
  end
45
46
  end
46
47
 
@@ -50,6 +51,10 @@ module Bridgetown
50
51
  configuration = set_color configuration, :blue, :bold
51
52
  say configuration
52
53
  end
54
+ say "\n"
55
+
56
+ docs_url = "https://www.bridgetownrb.com/docs/bundled-configurations".yellow.bold
57
+ say "For more info, check out the docs at: #{docs_url}"
53
58
  end
54
59
 
55
60
  def configurations
@@ -28,6 +28,7 @@ module Bridgetown
28
28
 
29
29
  def console
30
30
  require "irb"
31
+ require "irb/ext/save-history"
31
32
  require "amazing_print" unless options[:"bypass-ap"]
32
33
 
33
34
  Bridgetown.logger.info "Starting:", "Bridgetown v#{Bridgetown::VERSION.magenta}" \
@@ -50,6 +51,7 @@ module Bridgetown
50
51
  IRB.setup(nil)
51
52
  workspace = IRB::WorkSpace.new
52
53
  irb = IRB::Irb.new(workspace)
54
+ IRB.conf[:IRB_RC]&.call(irb.context)
53
55
  IRB.conf[:MAIN_CONTEXT] = irb.context
54
56
  eval("site = $BRIDGETOWN_SITE", workspace.binding, __FILE__, __LINE__)
55
57
  Bridgetown.logger.info "Console:", "Now loaded as " + "site".cyan + " variable."
@@ -68,6 +70,8 @@ module Bridgetown
68
70
  end
69
71
  irb.eval_input
70
72
  end
73
+ ensure
74
+ IRB.conf[:AT_EXIT].each(&:call)
71
75
  end
72
76
  end
73
77
  end
@@ -33,7 +33,6 @@ module Bridgetown
33
33
 
34
34
  def healthy?(site)
35
35
  [
36
- fsnotify_buggy?(site),
37
36
  !conflicting_urls(site),
38
37
  !urls_only_differ_by_case(site),
39
38
  proper_site_url?(site),
@@ -59,7 +58,7 @@ module Bridgetown
59
58
  conflicting_urls = false
60
59
  urls = {}
61
60
  urls = collect_urls(urls, site.pages, site.dest)
62
- urls = collect_urls(urls, site.posts.docs, site.dest)
61
+ urls = collect_urls(urls, site.collections.posts.docs, site.dest)
63
62
  urls.each do |url, paths|
64
63
  next unless paths.size > 1
65
64
 
@@ -70,23 +69,6 @@ module Bridgetown
70
69
  conflicting_urls
71
70
  end
72
71
 
73
- def fsnotify_buggy?(_site)
74
- return true unless Utils::Platforms.osx?
75
-
76
- if Dir.pwd != `pwd`.strip
77
- Bridgetown.logger.error " " + <<-STR.strip.gsub(%r!\n\s+!, "\n ")
78
- We have detected that there might be trouble using fsevent on your
79
- operating system, you can read https://github.com/thibaudgg/rb-fsevent/wiki/no-fsevents-fired-(OSX-bug)
80
- for possible work arounds or you can work around it immediately
81
- with `--force-polling`.
82
- STR
83
-
84
- false
85
- end
86
-
87
- true
88
- end
89
-
90
72
  def urls_only_differ_by_case(site)
91
73
  urls_only_differ_by_case = false
92
74
  urls = case_insensitive_urls(site.pages + site.docs_to_write, site.dest)
@@ -4,6 +4,7 @@ module Bridgetown
4
4
  module Commands
5
5
  class New < Thor::Group
6
6
  include Thor::Actions
7
+ include GitHelpers
7
8
  extend Summarizable
8
9
 
9
10
  Registrations.register do
@@ -157,8 +158,7 @@ module Bridgetown
157
158
  def git_init(path)
158
159
  unless Bridgetown.environment == "test"
159
160
  inside(path) do
160
- run "git init", abort_on_failure: true
161
- run "if [[ -n $(git status | grep 'On branch master') ]]; then git checkout -b main; fi"
161
+ initialize_new_repo
162
162
  end
163
163
  end
164
164
  rescue SystemExit
@@ -5,6 +5,7 @@ module Bridgetown
5
5
  class Plugins < Thor
6
6
  include Thor::Actions
7
7
  include ConfigurationOverridable
8
+ include GitHelpers
8
9
 
9
10
  Registrations.register do
10
11
  desc "plugins <command>", "List installed plugins or access plugin content"
@@ -144,15 +145,15 @@ module Bridgetown
144
145
  name = folder_name.dasherize
145
146
  module_name = folder_name.camelize
146
147
 
147
- run "git clone https://github.com/bridgetownrb/bridgetown-sample-plugin #{name}"
148
+ # TODO: upon 0.21 release, remove the explicit branch name!
149
+ run "git clone -b switch-to-minitest https://github.com/bridgetownrb/bridgetown-sample-plugin #{name}"
148
150
  new_gemspec = "#{name}.gemspec"
149
151
 
150
152
  inside name do # rubocop:todo Metrics/BlockLength
151
- run "rm -rf .git"
152
- run "git init"
153
- run "if [[ -n $(git status | grep 'On branch master') ]]; then git checkout -b main; fi"
153
+ destroy_existing_repo
154
+ initialize_new_repo
154
155
 
155
- run "mv bridgetown-sample-plugin.gemspec #{new_gemspec}"
156
+ FileUtils.mv "bridgetown-sample-plugin.gemspec", new_gemspec.to_s
156
157
  gsub_file new_gemspec, "https://github.com/bridgetownrb/bridgetown-sample-plugin", "https://github.com/username/#{name}"
157
158
  gsub_file new_gemspec, "bridgetown-sample-plugin", name
158
159
  gsub_file new_gemspec, "sample-plugin", name
@@ -161,21 +162,21 @@ module Bridgetown
161
162
  gsub_file "package.json", "https://github.com/bridgetownrb/bridgetown-sample-plugin", "https://github.com/username/#{name}"
162
163
  gsub_file "package.json", "bridgetown-sample-plugin", name
163
164
 
164
- run "mv lib/sample-plugin.rb lib/#{name}.rb"
165
+ FileUtils.mv "lib/sample-plugin.rb", "lib/#{name}.rb"
165
166
  gsub_file "lib/#{name}.rb", "sample-plugin", name
166
167
  gsub_file "lib/#{name}.rb", "SamplePlugin", module_name
167
168
 
168
- run "mv lib/sample-plugin lib/#{name}"
169
+ FileUtils.mv "lib/sample-plugin", "lib/#{name}"
169
170
  gsub_file "lib/#{name}/builder.rb", "SamplePlugin", module_name
170
171
  gsub_file "lib/#{name}/version.rb", "SamplePlugin", module_name
171
172
 
172
- run "mv spec/sample-plugin_spec.rb spec/#{name}_spec.rb"
173
- gsub_file "spec/#{name}_spec.rb", "SamplePlugin", module_name
174
- gsub_file "spec/spec_helper.rb", "sample-plugin", name
173
+ FileUtils.mv "test/test_sample_plugin.rb", "test/test_#{folder_name}.rb"
174
+ gsub_file "test/test_#{folder_name}.rb", "SamplePlugin", module_name
175
+ gsub_file "test/helper.rb", "sample-plugin", name
175
176
 
176
- run "mv components/sample_plugin components/#{folder_name}"
177
- run "mv content/sample_plugin content/#{folder_name}"
178
- run "mv layouts/sample_plugin layouts/#{folder_name}"
177
+ FileUtils.mv "components/sample_plugin", "components/#{folder_name}"
178
+ FileUtils.mv "content/sample_plugin", "content/#{folder_name}"
179
+ FileUtils.mv "layouts/sample_plugin", "layouts/#{folder_name}"
179
180
 
180
181
  gsub_file "layouts/#{folder_name}/layout.html", "sample_plugin", folder_name
181
182
  gsub_file "content/#{folder_name}/example_page.md", "sample_plugin", folder_name
@@ -13,10 +13,6 @@ module Bridgetown
13
13
 
14
14
  class_option :host, aliases: "-H", desc: "Host to bind to"
15
15
  class_option :port, aliases: "-P", desc: "Port to listen on"
16
- class_option :open_url,
17
- aliases: "-o",
18
- type: :boolean,
19
- desc: "Launch your site in a browser"
20
16
  class_option :detach,
21
17
  aliases: "-B",
22
18
  type: :boolean,
@@ -169,16 +165,6 @@ module Bridgetown
169
165
  )
170
166
  end
171
167
 
172
- def launch_browser(server, opts)
173
- address = server_address(server, opts)
174
- return system "start", address if Utils::Platforms.windows?
175
- return system "xdg-open", address if Utils::Platforms.linux?
176
- return system "open", address if Utils::Platforms.osx?
177
-
178
- Bridgetown.logger.error "Refusing to launch browser; " \
179
- "Platform launcher unknown."
180
- end
181
-
182
168
  # Keep in our area with a thread or detach the server as requested
183
169
  # by the user. This method determines what we do based on what you
184
170
  # ask us to do.
@@ -0,0 +1,178 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bridgetown
4
+ class Component
5
+ extend Forwardable
6
+
7
+ def_delegators :@view_context, :helpers, :liquid_render, :partial
8
+
9
+ # @return [Bridgetown::Site]
10
+ attr_reader :site # will be nil unless you explicitly set a `@site` ivar
11
+
12
+ # @return [Bridgetown::RubyTemplateView, Bridgetown::Component]
13
+ attr_reader :view_context
14
+
15
+ class << self
16
+ attr_accessor :source_location
17
+
18
+ def inherited(child)
19
+ # Code cribbed from ViewComponent by GitHub:
20
+ # Derive the source location of the component Ruby file from the call stack
21
+ child.source_location = caller_locations(1, 10).reject do |l|
22
+ l.label == "inherited"
23
+ end[0].absolute_path
24
+
25
+ super
26
+ end
27
+
28
+ # Return the appropriate template renderer for a given extension.
29
+ # TODO: make this extensible
30
+ #
31
+ # @param ext [String] erb, slim, etc.
32
+ def renderer_for_ext(ext, &block)
33
+ case ext
34
+ when "erb"
35
+ include ERBCapture
36
+ Tilt::ErubiTemplate.new(component_template_path,
37
+ outvar: "@_erbout",
38
+ bufval: "Bridgetown::OutputBuffer.new",
39
+ engine_class: Bridgetown::ERBEngine,
40
+ &block)
41
+ when "serb" # requires serbea
42
+ include Serbea::Helpers
43
+ Tilt::SerbeaTemplate.new(component_template_path, &block)
44
+ when "slim" # requires bridgetown-slim
45
+ Slim::Template.new(component_template_path, &block)
46
+ when "haml" # requires bridgetown-haml
47
+ Tilt::HamlTemplate.new(component_template_path, &block)
48
+ else
49
+ raise NameError
50
+ end
51
+ rescue NameError, LoadError
52
+ raise "No component rendering engine could be found for .#{ext} templates"
53
+ end
54
+
55
+ # Find the first matching template path based on source location and extension.
56
+ #
57
+ # @return [String]
58
+ def component_template_path
59
+ stripped_path = File.join(
60
+ File.dirname(source_location),
61
+ File.basename(source_location, ".*")
62
+ )
63
+ supported_template_extensions.each do |ext|
64
+ test_path = "#{stripped_path}.#{ext}"
65
+ return test_path if File.exist?(test_path)
66
+
67
+ test_path = "#{stripped_path}.html.#{ext}"
68
+ return test_path if File.exist?(test_path)
69
+ end
70
+
71
+ raise "No matching templates could be found in #{File.dirname(source_location)}"
72
+ end
73
+
74
+ # Read the template file.
75
+ #
76
+ # @return [String]
77
+ def component_template_content
78
+ File.read(component_template_path)
79
+ end
80
+
81
+ # A list of extensions supported by the renderer
82
+ # TODO: make this extensible
83
+ #
84
+ # @return [Array<String>]
85
+ def supported_template_extensions
86
+ %w(erb serb slim haml)
87
+ end
88
+ end
89
+
90
+ # If a content block was originally passed into via `render`, capture its output.
91
+ #
92
+ # @return [String] or nil
93
+ def content
94
+ @_content ||= begin
95
+ view_context.capture(self, &@_content_block) if @_content_block
96
+ end
97
+ end
98
+
99
+ # Provide a render helper for evaluation within the component context.
100
+ #
101
+ # @param item [Object] a component supporting `render_in` or a partial name
102
+ # @param options [Hash] passed to the `partial` helper if needed
103
+ # @return [String]
104
+ def render(item, options = {}, &block)
105
+ if item.respond_to?(:render_in)
106
+ result = ""
107
+ capture do # this ensures no leaky interactions between BT<=>VC blocks
108
+ result = item.render_in(self, &block)
109
+ end
110
+ result&.html_safe
111
+ else
112
+ partial(item, options, &block)&.html_safe
113
+ end
114
+ end
115
+
116
+ # This is where the magic happens. Render the component within a view context.
117
+ #
118
+ # @param view_context [Bridgetown::RubyTemplateView]
119
+ def render_in(view_context, &block)
120
+ @view_context = view_context
121
+ @_content_block = block
122
+
123
+ if render?
124
+ before_render
125
+ template
126
+ else
127
+ ""
128
+ end
129
+ rescue StandardError => e
130
+ Bridgetown.logger.error "Component error:",
131
+ "#{self.class} encountered an error while "\
132
+ "rendering `#{self.class.component_template_path}'"
133
+ raise e
134
+ end
135
+
136
+ # Subclasses can override this method to return a string from their own
137
+ # template handling.
138
+ def template
139
+ call || _renderer.render(self)
140
+ end
141
+
142
+ # Typically not used but here as a compatibility nod toward ViewComponent.
143
+ def call
144
+ nil
145
+ end
146
+
147
+ # Subclasses can override this method to perform tasks before a render.
148
+ def before_render; end
149
+
150
+ # Subclasses can override this method to determine if the component should
151
+ # be rendered based on initialized data or other logic.
152
+ def render?
153
+ true
154
+ end
155
+
156
+ def _renderer
157
+ # TODO: figure out a way to compile templates for increased performance
158
+ @_renderer ||= begin
159
+ ext = File.extname(self.class.component_template_path).delete_prefix(".")
160
+ self.class.renderer_for_ext(ext) { self.class.component_template_content }
161
+ end
162
+ end
163
+
164
+ # rubocop:disable Style/MissingRespondToMissing
165
+ ruby2_keywords def method_missing(method, *args, &block)
166
+ if helpers.respond_to?(method.to_sym)
167
+ helpers.send method.to_sym, *args, &block
168
+ else
169
+ super
170
+ end
171
+ end
172
+
173
+ def respond_to_missing?(method, include_private = false)
174
+ helpers.respond_to?(method.to_sym, include_private) || super
175
+ end
176
+ # rubocop:enable Style/MissingRespondToMissing
177
+ end
178
+ end