Module: Neuron::View
- Extended by:
- ActiveSupport::Memoizable
- Defined in:
- lib/neuron/view.rb
Class Method Summary collapse
Instance Method Summary collapse
- #block_modifiers(block, *modifiers) ⇒ Object
-
#body_attributes ⇒ Object
Make body’s modifiers, based on controller_name and action_name.
-
#canonical_path(resource, options = {}) ⇒ Object
Build canonical path for given resource.
-
#canonical_url(resource, options = {}) ⇒ Object
Build canonical url for given resource.
- #controller_i18n_scope ⇒ Object
- #date(date, options = {}) ⇒ Object
- #html_attributes ⇒ Object
- #human(klass, attribute = nil) ⇒ Object
- #time(time, options = {}) ⇒ Object
- #view_name ⇒ Object
Class Method Details
.setup! ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/neuron/view.rb', line 7 def self.setup! if defined?(::ActionView) ActionView::Base.send(:include, Neuron::View) ActionView::Base.send(:include, Neuron::::View) ActionView::Base.send(:include, Neuron::Resources::View) if defined?(::InheritedResources) ActionView::Base.send(:include, Neuron::Authorization::View) if defined?(::CanCan) ActionView::Base.send(:include, Neuron::ShowFor::Helper) if defined?(::ShowFor) end end |
Instance Method Details
#block_modifiers(block, *modifiers) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/neuron/view.rb', line 17 def block_modifiers(block, *modifiers) klasses = [block] if ( = modifiers.).any? .each do |modifier, needed| klasses << "#{block}_#{modifier}" if needed end end klasses += modifiers.collect { |modifier| "#{block}_#{modifier}" } {:class => klasses.join(' ')} end |
#body_attributes ⇒ Object
Make body’s modifiers, based on controller_name and action_name
29 30 31 32 33 34 |
# File 'lib/neuron/view.rb', line 29 def body_attributes controller_class = controller_i18n_scope.gsub(/[._]/, '-') block_modifiers("m-#{controller_class}", view_name).tap do |hash| hash[:class] << " m-action_#{view_name}" end end |
#canonical_path(resource, options = {}) ⇒ Object
Build canonical path for given resource
51 52 53 |
# File 'lib/neuron/view.rb', line 51 def canonical_path(resource, = {}) canonical_url(resource, .merge(routing_type: :path)) end |
#canonical_url(resource, options = {}) ⇒ Object
Build canonical url for given resource
46 47 48 |
# File 'lib/neuron/view.rb', line 46 def canonical_url(resource, = {}) polymorphic_url(resource, ) end |
#controller_i18n_scope ⇒ Object
59 60 61 |
# File 'lib/neuron/view.rb', line 59 def controller_i18n_scope controller.controller_path.gsub(%r{/}, '.') end |
#date(date, options = {}) ⇒ Object
73 74 75 |
# File 'lib/neuron/view.rb', line 73 def date(date, = {}) time(date.to_date) end |
#html_attributes ⇒ Object
36 37 38 |
# File 'lib/neuron/view.rb', line 36 def html_attributes {:lang => I18n.locale} end |
#human(klass, attribute = nil) ⇒ Object
40 41 42 |
# File 'lib/neuron/view.rb', line 40 def human(klass, attribute = nil) attribute ? klass.human_attribute_name(attribute) : klass.name.human end |
#time(time, options = {}) ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/neuron/view.rb', line 64 def time(time, = {}) format = .delete(:format) { :short } title = .delete(:title) do title_format = .delete(:title_format) { :long } l(time, format: title_format) end content_tag(:time, l(time, format: format), .merge(datetime: time.xmlschema, title: title)) end |
#view_name ⇒ Object
55 56 57 |
# File 'lib/neuron/view.rb', line 55 def view_name {create: 'new', update: 'edit'}[action_name] || action_name end |