Module: Neuron::View

Extended by:
ActiveSupport::Memoizable
Defined in:
lib/neuron/view.rb

Class Method Summary collapse

Instance Method Summary collapse

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::Navigation::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 (options = modifiers.extract_options!).any?
    options.each do |modifier, needed|
      klasses << "#{block}_#{modifier}" if needed
    end
  end
  klasses += modifiers.collect { |modifier| "#{block}_#{modifier}" }
  {:class => klasses.join(' ')}
end

#body_attributesObject

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, options = {})
  canonical_url(resource, options.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, options = {})
  polymorphic_url(resource, options)
end

#controller_i18n_scopeObject



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, options = {})
  time(date.to_date)
end

#html_attributesObject



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, options = {})
  format        = options.delete(:format) { :short }
  title  = options.delete(:title) do
    title_format  = options.delete(:title_format) { :long }
    l(time, format: title_format)
  end
  (:time, l(time, format: format), options.merge(datetime: time.xmlschema, title: title))
end

#view_nameObject



55
56
57
# File 'lib/neuron/view.rb', line 55

def view_name
  {create: 'new', update: 'edit'}[action_name] || action_name
end