Module: Fluxbit::ComponentsHelper
- Defined in:
- app/helpers/fluxbit/components_helper.rb
Instance Method Summary collapse
- #fluxbit_method(method_name, *args, **kwargs, &c) ⇒ Object
- #form_builder ⇒ Object
-
#fx_heading ⇒ Object
Typography.
- #fx_link_to(body = nil, url = nil, **kwargs, &block) ⇒ Object
- #fx_link_to_old(body, url, **kwargs, &block) ⇒ Object
-
#fx_select(name = nil, option_tags = nil, options = {}, &block) ⇒ Object
Mimics Rails’ select_tag signature: select_tag(name, option_tags = nil, options = {}).
- #fx_txt ⇒ Object
Instance Method Details
#fluxbit_method(method_name, *args, **kwargs, &c) ⇒ Object
107 108 109 110 111 112 113 114 115 |
# File 'app/helpers/fluxbit/components_helper.rb', line 107 def fluxbit_method(method_name, *args, **kwargs, &c) component_klass = "Fluxbit::#{method_name}Component".constantize if kwargs[:with_content] content = kwargs.delete(:with_content) render(component_klass.new(*args, **kwargs).with_content(content), &c) else render(component_klass.new(*args, **kwargs), &c) end end |
#form_builder ⇒ Object
59 |
# File 'app/helpers/fluxbit/components_helper.rb', line 59 def form_builder(...) = fluxbit_method("Form::FormBuilder", ...) |
#fx_heading ⇒ Object
Typography
74 |
# File 'app/helpers/fluxbit/components_helper.rb', line 74 def fx_heading(...) = fluxbit_method("Heading", ...) |
#fx_link_to(body = nil, url = nil, **kwargs, &block) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'app/helpers/fluxbit/components_helper.rb', line 85 def fx_link_to(body = nil, url = nil, **kwargs, &block) kwargs[:as] = :a if block_given? && body.is_a?(String) && (url.is_a?(String) || url.is_a?(Symbol)) # Handle case: fx_link_to("Link text", "/path") { ... } kwargs[:href] = url fluxbit_method("Link", as: :a, content: body, **kwargs, &block) elsif block_given? && body.is_a?(String) && url.nil? # Handle case: fx_link_to("/path") { ... content ... } kwargs[:href] = body # first arg is URL fluxbit_method("Link", as: :a, **kwargs, &block) elsif !block_given? && body.is_a?(String) && (url.is_a?(String) || url.is_a?(Symbol)) # Handle case: fx_link_to("Link text", "/path", class: "...") component_klass = "Fluxbit::LinkComponent".constantize kwargs[:href] = url render(component_klass.new(**kwargs).with_content(body)) else # Handle other cases or provide feedback raise ArgumentError, "Invalid arguments for fx_link_to" end end |
#fx_link_to_old(body, url, **kwargs, &block) ⇒ Object
78 79 80 81 82 83 |
# File 'app/helpers/fluxbit/components_helper.rb', line 78 def fx_link_to_old(body, url, **kwargs, &block) kwargs[:body] = body if body.is_a?(String) kwargs[:url] = url if url.is_a?(String) kwargs[:with_content] = block if block_given? Fluxbit::TextComponent.new(body, url, **kwargs).render(&block) end |
#fx_select(name = nil, option_tags = nil, options = {}, &block) ⇒ Object
Mimics Rails’ select_tag signature: select_tag(name, option_tags = nil, options = {})
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/helpers/fluxbit/components_helper.rb', line 40 def fx_select(name = nil, = nil, = {}, &block) # Handle both positional and named parameters if name.is_a?(Hash) # Named parameters: fx_select(name: "role", options: [...], prompt: "...") = name name = .delete(:name) = .delete(:options) || .delete(:choices) elsif .is_a?(Hash) && .empty? # Two args with second being options: fx_select("role", prompt: "...") = = .delete(:options) || .delete(:choices) end # Set the options/choices [:options] = if .present? [:name] = name if name.present? fluxbit_method("Form::Select", **, &block) end |
#fx_txt ⇒ Object
75 |
# File 'app/helpers/fluxbit/components_helper.rb', line 75 def fx_txt(...) = fluxbit_method("Text", ...) |