Module: RailsComponents

Defined in:
lib/rails_components/html_helpers.rb,
lib/rails_components.rb,
lib/rails_components/configuration.rb

Overview

Defined Under Namespace

Modules: HtmlHelpers Classes: Configuration

Constant Summary collapse

COMPONENT_RESERVED_WORDS =
%i(class return super).freeze

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.configurationObject

Returns the value of attribute configuration.



4
5
6
# File 'lib/rails_components/configuration.rb', line 4

def configuration
  @configuration
end

Class Method Details

.configure {|configuration| ... } ⇒ Object

Yields:



11
12
13
# File 'lib/rails_components/configuration.rb', line 11

def self.configure
  yield(configuration) if block_given?
end

Instance Method Details

#component(component_template, text_or_locals_with_block = nil, locals = nil, &block) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/rails_components.rb', line 7

def component(component_template, text_or_locals_with_block = nil, locals = nil, &block)
  if RailsComponents.configuration.template_directory
    component_template = [RailsComponents.configuration.template_directory, component_template].join('/')
  end

  if block_given?
    render({ layout: component_template, locals: component_locals(text_or_locals_with_block) }, &block)
  elsif text_or_locals_with_block.is_a?(Hash) && locals.nil?
    render(layout: component_template, locals: component_locals(text_or_locals_with_block)) {}
  else
    render(layout: component_template, locals: component_locals(locals)) { text_or_locals_with_block }
  end
end

#component_content_tag(props, name, content_or_options_with_block = nil, options = nil, escape = true, &block) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/rails_components.rb', line 23

def (props, name, content_or_options_with_block = nil, options = nil, escape = true, &block)
  if block_given?
    content_or_options_with_block = props.merge_html(content_or_options_with_block) if content_or_options_with_block.is_a? Hash
    (name, content_or_options_with_block, options, escape, &block)
  else
    options = props.merge_html(options)
    (name, content_or_options_with_block, options, escape, &block)
  end
end