Module: NitroRails::NitroTagHelper
- Defined in:
- app/helpers/nitro_rails/nitro_tag_helper.rb
Instance Method Summary collapse
- #body_options(**options) ⇒ Object
- #current_nitro_resource ⇒ Object
- #nitro_attribute(resource = current_nitro_resource, attribute, **options) ⇒ Object
-
#nitro_attribute_tag(tag_or_resource = :p, maybe_resource = current_nitro_resource, attribute, **options, &block) ⇒ Object
ATTRIBUTE ##.
-
#nitro_body_tag(**options, &block) ⇒ Object
BODY ##.
-
#nitro_link_tag(*args, **options, &block) ⇒ Object
(also: #nitro_link)
LINK ##.
- #nitro_resource(resource, **options, &block) ⇒ Object
-
#nitro_resource_tag(tag = :div, resource, **options, &block) ⇒ Object
RESOURCE ##.
- #nitro_tag(tag = :div, text = nil, nitro_id: nil, link: nil, **options, &block) ⇒ Object
- #with_nitro_resource(resource) ⇒ Object
Instance Method Details
#body_options(**options) ⇒ Object
43 44 45 |
# File 'app/helpers/nitro_rails/nitro_tag_helper.rb', line 43 def (**) @custom_body_options = end |
#current_nitro_resource ⇒ Object
96 97 98 |
# File 'app/helpers/nitro_rails/nitro_tag_helper.rb', line 96 def current_nitro_resource @_nitro_resource_stack&.last end |
#nitro_attribute(resource = current_nitro_resource, attribute, **options) ⇒ Object
144 145 146 |
# File 'app/helpers/nitro_rails/nitro_tag_helper.rb', line 144 def nitro_attribute(resource = current_nitro_resource, attribute, **) nitro_attribute_tag(.delete(:tag) || :p, resource, attribute, **) end |
#nitro_attribute_tag(tag_or_resource = :p, maybe_resource = current_nitro_resource, attribute, **options, &block) ⇒ Object
ATTRIBUTE ##
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'app/helpers/nitro_rails/nitro_tag_helper.rb', line 104 def nitro_attribute_tag(tag_or_resource = :p, maybe_resource = current_nitro_resource, attribute, **, &block) # Not sure this works for all cases # nitro_attribute_tag(:p, @task, :name, **options) # nitro_attribute_tag(@task, :name, **options) # nitro_attribute_tag(:name, **options) # nitro_attribute_tag(:p, :name, **options) # ## First argument can be tag, resource, or attribute ## Second argument can be resource or attribute ## Third argument is always attribute if tag_or_resource.is_a?(Symbol) || tag_or_resource.is_a?(String) tag = tag_or_resource resource = maybe_resource else tag = :p resource = tag_or_resource end () do || .default(:nitro_id, resource.nitro_id(attribute)) .concat(:class, classify(attribute)) .concat(:class, classify(resource.type, attribute)) .concat(:class, attribute_status_class(resource, attribute)) end # NEW CODE value = resource.send(attribute) if [:format] && value.present? .delete(:format).each do |method, params| value = value.send(method, *params) end end value = value.presence || .delete(:default) || "" # END NEW CODE nitro_tag(tag, value, **, &block) end |
#nitro_body_tag(**options, &block) ⇒ Object
BODY ##
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/helpers/nitro_rails/nitro_tag_helper.rb', line 15 def nitro_body_tag(**, &block) .merge!(@custom_body_options) if @custom_body_options (, @custom_body_options) do || .concat(:class, .delete(:color_scheme) || current_color_scheme) .concat(:class, "#{controller_name}-#{action_name}") if turbo_native_app? .concat(:class, "turbo-native") if ios_app? .concat(:class, "ios") .override(:data, :turbo_native, "iOS") elsif android_app? .concat(:class, "android") .override(:data, :turbo_native, "Android") end end .concat(:data, :controller, "panel-manager time-zone nitro") .concat(:data, :action, "turbo@morph->panel-manager#morph click->panel-manager#closeOtherPanels touchend->panel-manager#closeOtherPanels") .default(:data, :panel_manager_target, "container") .default(:data, :time_zone_server_time_value, "#{Time.now.utc.iso8601}") end content_tag(:body, **, &block) # Should use nitro_tag end |
#nitro_link_tag(*args, **options, &block) ⇒ Object Also known as: nitro_link
LINK ##
51 52 53 54 55 56 57 58 |
# File 'app/helpers/nitro_rails/nitro_tag_helper.rb', line 51 def nitro_link_tag(*args, **, &block) () do || .concat(:class, "nitro-link") .concat(:class, "active") if current_page?(args.last) end link_to(*args, **, &block) end |
#nitro_resource(resource, **options, &block) ⇒ Object
85 86 87 |
# File 'app/helpers/nitro_rails/nitro_tag_helper.rb', line 85 def nitro_resource(resource, **, &block) nitro_resource_tag(.delete(:tag) || :div, resource, **, &block) end |
#nitro_resource_tag(tag = :div, resource, **options, &block) ⇒ Object
RESOURCE ##
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'app/helpers/nitro_rails/nitro_tag_helper.rb', line 66 def nitro_resource_tag(tag = :div, resource, **, &block) () do || .default(:nitro_id, resource.nitro_id) # Maybe add default? .default(:data, :id, resource.id) .concat(:class, classify(resource.type)) .concat(:class, resource_status_classes(resource)) .concat(:class, "hover-context") unless [:hover_context] == false if link = .delete(:link) .default(:data, :action, "click->nitro#link") .default(:data, :nitro_link, link == true ? url_for(resource) : link) end end with_nitro_resource(resource) do nitro_tag(tag, **, &block) end end |
#nitro_tag(tag = :div, text = nil, nitro_id: nil, link: nil, **options, &block) ⇒ Object
3 4 5 6 7 8 9 |
# File 'app/helpers/nitro_rails/nitro_tag_helper.rb', line 3 def nitro_tag(tag = :div, text = nil, nitro_id: nil, link: nil, **, &block) () do || .default(:data, :nitro_id, nitro_id) if nitro_id end content_tag(tag, text, **, &block) end |
#with_nitro_resource(resource) ⇒ Object
89 90 91 92 93 94 |
# File 'app/helpers/nitro_rails/nitro_tag_helper.rb', line 89 def with_nitro_resource(resource) (@_nitro_resource_stack ||= []).push(resource) yield ensure @_nitro_resource_stack.pop end |