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, &block) ⇒ Object
- #form_options_defaults!(options) ⇒ Object
- #form_with(model: nil, scope: nil, url: nil, format: nil, **options, &block) ⇒ 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 |
# 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 :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
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/satis/helpers/container.rb', line 65 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
34 35 36 |
# File 'lib/satis/helpers/container.rb', line 34 def browser @browser ||= Browser.new(action_view.request.user_agent) end |
#copyable(name, scrub: "#") ⇒ Object
28 29 30 31 32 |
# File 'lib/satis/helpers/container.rb', line 28 def copyable(name, scrub: "#") return if name.blank? action_view.content_tag("satis-copyable", name, scrub: scrub) end |
#form_for(name, *args, &block) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/satis/helpers/container.rb', line 38 def form_for(name, *args, &block) = args..deep_merge!(html: { data: {} }) () ([:html][:data], ) args << .merge(builder: Satis::Forms::Builder) action_view.form_for(name, *args, &block) end |
#form_options_defaults!(options) ⇒ Object
53 54 55 56 |
# File 'lib/satis/helpers/container.rb', line 53 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, &block) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/satis/helpers/container.rb', line 46 def form_with(model: nil, scope: nil, url: nil, format: nil, **, &block) = .reverse_merge(builder: Satis::Forms::Builder, class: "").deep_merge!(data: {}) () ([:data], ) action_view.form_with(model: model, scope: scope, url: url, format: format, **, &block) end |
#update_form_data_options!(data, options) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/satis/helpers/container.rb', line 58 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 |