Module: AmberComponent::Rendering::ClassMethods
- Included in:
- Base
- Defined in:
- lib/amber_component/rendering.rb
Overview
Class methods for rendering.
Instance Method Summary collapse
- #compile(force: false) ⇒ void
- #compile? ⇒ Boolean
- #compiled? ⇒ Boolean
- #render(**kwargs, &block) ⇒ String (also: #call)
- #template_handler ⇒ Class?
Instance Method Details
#compile(force: false) ⇒ void
This method returns an undefined value.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/amber_component/rendering.rb', line 34 def compile(force: false) return if !compile? && !force return if template_handler.nil? render_template_method_redefinition_lock.synchronize do silence_redefinition_of_method(RENDER_TEMPLATE_METHOD_NAME) # rubocop:disable Style/EvalWithLocation class_eval <<~CODE, view_path.to_s, 0 # rubocop:disable Style/DocumentDynamicEvalDefinition def #{RENDER_TEMPLATE_METHOD_NAME}(local_assigns, output_buffer, &block) #{compiled_template_source} end CODE # rubocop:enable Style/EvalWithLocation end end |
#compile? ⇒ Boolean
26 27 28 29 30 |
# File 'lib/amber_component/rendering.rb', line 26 def compile? return true if defined?(::Rails.env) && ::Rails.env.development? !compiled? end |
#compiled? ⇒ Boolean
21 22 23 |
# File 'lib/amber_component/rendering.rb', line 21 def compiled? method_defined?(RENDER_TEMPLATE_METHOD_NAME) end |
#render(**kwargs, &block) ⇒ String Also known as: call
14 15 16 |
# File 'lib/amber_component/rendering.rb', line 14 def render(**kwargs, &block) new(**kwargs).render(&block) end |
#template_handler ⇒ Class?
51 52 53 |
# File 'lib/amber_component/rendering.rb', line 51 def template_handler @template_handler ||= ::ActionView::Template.registered_template_handler(view_type) end |