Class: RailsViewComponentModel
- Inherits:
-
Object
- Object
- RailsViewComponentModel
- Defined in:
- lib/generators/rails_view_component/templates/rails_view_component_model.rb
Instance Attribute Summary collapse
-
#component_name ⇒ Object
readonly
Returns the value of attribute component_name.
-
#html_classes ⇒ Object
readonly
Returns the value of attribute html_classes.
-
#html_identifier ⇒ Object
readonly
Returns the value of attribute html_identifier.
Instance Method Summary collapse
- #html(erb_params = {}, ajax_params = {}) ⇒ Object
-
#initialize(id) ⇒ RailsViewComponentModel
constructor
A new instance of RailsViewComponentModel.
- #javascripts ⇒ Object
- #responsibility ⇒ Object
- #stylesheets ⇒ Object
Constructor Details
#initialize(id) ⇒ RailsViewComponentModel
3 4 5 6 7 8 9 10 |
# File 'lib/generators/rails_view_component/templates/rails_view_component_model.rb', line 3 def initialize id @prefix = "rails_view_component" @components = self.class.name.underscore.split("/")[0..-2] @dir = @components.join("/") @html_class_name = @prefix + "-" + @components.join("-") @html_identifier = "#{@html_class_name}-#{id}" @html_classes = ["rails_view_component", @html_class_name] end |
Instance Attribute Details
#component_name ⇒ Object (readonly)
Returns the value of attribute component_name.
2 3 4 |
# File 'lib/generators/rails_view_component/templates/rails_view_component_model.rb', line 2 def component_name @component_name end |
#html_classes ⇒ Object (readonly)
Returns the value of attribute html_classes.
2 3 4 |
# File 'lib/generators/rails_view_component/templates/rails_view_component_model.rb', line 2 def html_classes @html_classes end |
#html_identifier ⇒ Object (readonly)
Returns the value of attribute html_identifier.
2 3 4 |
# File 'lib/generators/rails_view_component/templates/rails_view_component_model.rb', line 2 def html_identifier @html_identifier end |
Instance Method Details
#html(erb_params = {}, ajax_params = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/generators/rails_view_component/templates/rails_view_component_model.rb', line 23 def html erb_params={}, ajax_params={} action_view = ActionView::Base.new "#{Rails.root}/app/rails_view_components/#{@dir}/views" erb_params.each{|k,v| action_view.assign(k=>v) } data = ajax_params.map{|k,v| "data-#{k}='#{v}'" }.join(' ') return <<HTML <div id="#{@html_identifier}" class="#{@html_classes.join(' ')}" #{data}> #{action_view.render(template: self.erb_script)} </div> HTML end |
#javascripts ⇒ Object
16 17 18 |
# File 'lib/generators/rails_view_component/templates/rails_view_component_model.rb', line 16 def javascripts [] end |
#responsibility ⇒ Object
12 13 14 |
# File 'lib/generators/rails_view_component/templates/rails_view_component_model.rb', line 12 def responsibility 1 end |
#stylesheets ⇒ Object
19 20 21 |
# File 'lib/generators/rails_view_component/templates/rails_view_component_model.rb', line 19 def stylesheets [] end |