Module: AmberComponent::Views::ClassMethods
- Included in:
- Base
- Defined in:
- lib/amber_component/views.rb
Overview
Class methods for views.
Instance Attribute Summary collapse
-
#method_view ⇒ TypedContent
readonly
ERB/Haml/Slim view registered through the
viewmethod.
Instance Method Summary collapse
-
#view(type = :erb, &block) ⇒ void
Register an inline view by returning a String from the passed block.
- #view_file_name ⇒ String?
- #view_path ⇒ String
- #view_type ⇒ Symbol
Instance Attribute Details
#method_view ⇒ TypedContent (readonly)
ERB/Haml/Slim view registered through the view method.
48 49 50 |
# File 'lib/amber_component/views.rb', line 48 def method_view @method_view end |
Instance Method Details
#view(type = :erb, &block) ⇒ void
This method returns an undefined value.
Register an inline view by returning a String from the passed block.
Usage:
view do
<<~ERB
<h1>
Hello <%= @name %>
</h1>
ERB
end
or:
view :haml do
<<~HAML
%h1
Hello
= @name
HAML
end
41 42 43 |
# File 'lib/amber_component/views.rb', line 41 def view(type = :erb, &block) @method_view = TypedContent.new(type: type, content: block) end |
#view_file_name ⇒ String?
56 57 58 59 60 61 |
# File 'lib/amber_component/views.rb', line 56 def view_file_name files = asset_file_names(VIEW_FILE_REGEXP) raise MultipleViewsError, "More than one view file for `#{name}` found!" if files.length > 1 files.first end |
#view_path ⇒ String
51 52 53 |
# File 'lib/amber_component/views.rb', line 51 def view_path asset_path view_file_name end |
#view_type ⇒ Symbol
64 65 66 |
# File 'lib/amber_component/views.rb', line 64 def view_type (view_file_name.split('.')[1..].grep_v(/erb/).last || 'erb')&.to_sym end |