Module: Ballast::Concerns::View
- Defined in:
- lib/ballast/concerns/view.rb
Overview
A concern to help view handling.
Instance Method Summary (collapse)
-
- (Object) add_javascript_params(key, data, replace = false)
Appends new Javascript parameters.
-
- (Browser) browser
Returns an instance of the browser.
-
- (Boolean) browser_supported?(conf_file = nil)
Checks if the current browser is supported according to a definition YAML file.
-
- (String|Hash) javascript_params(id = nil, tag = :details)
Outputs the Javascript parameters.
-
- (Object|Hash) layout_params(key = nil, default_value = nil)
(also: #layout_param)
Returns one or all layout parameters.
-
- (String) scope_css
Scopes the CSS of the current page using the controller and action name.
-
- (Object) set_layout_params(**args)
Adds/Replaces layout parameters.
Instance Method Details
- (Object) add_javascript_params(key, data, replace = false)
Appends new Javascript parameters.
67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/ballast/concerns/view.rb', line 67 def add_javascript_params(key, data, replace = false) initialize_view_params if key @javascript_params[key] = nil if replace @javascript_params[key] ||= {} @javascript_params[key].merge!(data) elsif replace @javascript_params = data.with_indifferent_access else @javascript_params.merge!(data) end end |
- (Browser) browser
Returns an instance of the browser.
20 21 22 |
# File 'lib/ballast/concerns/view.rb', line 20 def browser @browser ||= Brauser::Browser.new(request.user_agent) end |
- (Boolean) browser_supported?(conf_file = nil)
Checks if the current browser is supported according to a definition YAML file.
28 29 30 31 |
# File 'lib/ballast/concerns/view.rb', line 28 def browser_supported?(conf_file = nil) conf_file ||= (Rails.root + "config/supported-browsers.yml").to_s if defined?(Rails) browser.supported?(conf_file) end |
- (String|Hash) javascript_params(id = nil, tag = :details)
Outputs the Javascript parameters.
57 58 59 60 |
# File 'lib/ballast/concerns/view.rb', line 57 def javascript_params(id = nil, tag = :details) initialize_view_params id ? content_tag(tag, @javascript_params.to_json.html_safe, "data-jid" => id): @javascript_params end |
- (Object|Hash) layout_params(key = nil, default_value = nil) Also known as: layout_param
Returns one or all layout parameters.
38 39 40 41 |
# File 'lib/ballast/concerns/view.rb', line 38 def layout_params(key = nil, default_value = nil) initialize_view_params key ? @layout_params.fetch(key, default_value) : @layout_params end |
- (String) scope_css
Scopes the CSS of the current page using the controller and action name.
13 14 15 |
# File 'lib/ballast/concerns/view.rb', line 13 def scope_css "%s %s" % [controller_path.gsub("/", "-"), action_name] end |
- (Object) set_layout_params(**args)
Adds/Replaces layout parameters.
47 48 49 50 |
# File 'lib/ballast/concerns/view.rb', line 47 def set_layout_params(**args) initialize_view_params @layout_params.merge!(args) end |