Class: Satis::Helpers::Container
- Inherits:
-
Object
- Object
- Satis::Helpers::Container
- Defined in:
- lib/satis/helpers/container.rb
Instance Attribute Summary collapse
-
#action_view ⇒ Object
readonly
Returns the value of attribute action_view.
Class Method Summary collapse
Instance Method Summary collapse
- #browser ⇒ Object
- #copyable(name, scrub: "#") ⇒ Object
- #form_for(name, *args) ⇒ Object
- #form_options_defaults!(options) ⇒ Object
- #form_with(model: nil, scope: nil, url: nil, format: nil, **options) ⇒ Object
-
#initialize(action_view) ⇒ Container
constructor
A new instance of Container.
- #update_form_data_options!(data, options) ⇒ Object
Constructor Details
#initialize(action_view) ⇒ Container
Returns a new instance of Container.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/satis/helpers/container.rb', line 8 def initialize(action_view) @action_view = action_view add_helper :appearance_switcher, Satis::AppearanceSwitcher::Component add_helper :avatar, Satis::Avatar::Component add_helper :breadcrumbs, Satis::Breadcrumbs::Component add_helper :card, Satis::Card::Component add_helper :call_to_action, Satis::CallToAction::Component add_helper :editor, Satis::Editor::Component add_helper :flash_messages, Satis::FlashMessages::Component add_helper :info, Satis::Info::Component add_helper :map, Satis::Map::Component add_helper :menu, Satis::Menu::Component add_helper :page, Satis::Page::Component add_helper :sidebar_menu, Satis::SidebarMenu::Component add_helper :tabs, Satis::Tabs::Component add_helper :input, Satis::Input::Component add_helper :progress_bar, Satis::ProgressBar::Component add_helper :dialog, Satis::Dialog::Component end |
Instance Attribute Details
#action_view ⇒ Object (readonly)
Returns the value of attribute action_view.
4 5 6 |
# File 'lib/satis/helpers/container.rb', line 4 def action_view @action_view end |
Class Method Details
.add_helper(name, component) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/satis/helpers/container.rb', line 66 def self.add_helper(name, component) if respond_to?(name) Satis.config.logger.warn("Helper #{name} already defined, skipping.") return end define_method(name) do |*args, **kwargs, &block| original_args = args.dup = args. instance = if .key? :variant variant_component = component.to_s.sub(/::Component$/, "::#{[:variant].to_s.camelize}::Component").safe_constantize (variant_component || component).new(*original_args, **kwargs) else component.new(*original_args, **kwargs) end instance.original_view_context = action_view action_view.render(instance, &block) end end |
Instance Method Details
#browser ⇒ Object
35 36 37 |
# File 'lib/satis/helpers/container.rb', line 35 def browser @browser ||= Browser.new(action_view.request.user_agent) end |
#copyable(name, scrub: "#") ⇒ Object
29 30 31 32 33 |
# File 'lib/satis/helpers/container.rb', line 29 def copyable(name, scrub: "#") return if name.blank? action_view.content_tag("satis-copyable", name, scrub: scrub) end |
#form_for(name, *args) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/satis/helpers/container.rb', line 39 def form_for(name, *args, &) = args..deep_merge!(html: {data: {}}) () ([:html][:data], ) args << .merge(builder: Satis::Forms::Builder) action_view.form_for(name, *args, &) end |
#form_options_defaults!(options) ⇒ Object
54 55 56 57 |
# File 'lib/satis/helpers/container.rb', line 54 def () [:submit_on_enter] = Satis.submit_on_enter? if [:submit_on_enter].nil? [:confirm_before_leave] = Satis.confirm_before_leave? if [:confirm_before_leave].nil? end |
#form_with(model: nil, scope: nil, url: nil, format: nil, **options) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/satis/helpers/container.rb', line 47 def form_with(model: nil, scope: nil, url: nil, format: nil, **, &) = .reverse_merge(builder: Satis::Forms::Builder, class: "").deep_merge!(data: {}) () ([:data], ) action_view.form_with(model: model, scope: scope, url: url, format: format, **, &) end |
#update_form_data_options!(data, options) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/satis/helpers/container.rb', line 59 def (data, ) data[:controller] ||= "" data[:controller] += " form" data[:"form-no-submit-on-enter-value"] = ![:submit_on_enter] data[:"form-confirm-before-leave-value"] = [:confirm_before_leave] end |