Module: Magazine::ApplicationHelper

Included in:
ArticlesController
Defined in:
app/helpers/magazine/application_helper.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'app/helpers/magazine/application_helper.rb', line 21

def method_missing method, *args, &block
  if method.to_s.end_with?('_path') or method.to_s.end_with?('_url')
    if main_app.respond_to?(method)
      main_app.send(method, *args)
    else
      super
    end
  else
    super
  end
end

Instance Method Details

#magazine_image_path(path, options = {}) ⇒ Object



7
8
9
10
11
12
# File 'app/helpers/magazine/application_helper.rb', line 7

def magazine_image_path(path, options = {})
  category = _magazine_val(:category, options)
  article = _magazine_val(:article, options)

  image_path(['magazine', category.try(:category_slug), article.try(:slug), path].compact.join('/'))
end

#magazine_image_tag(path, options = {}) ⇒ Object



3
4
5
# File 'app/helpers/magazine/application_helper.rb', line 3

def magazine_image_tag(path, options = {})
  image_tag(magazine_image_path(path, options), options.except(:category, 'category'))
end

#magazine_inside_public_period?(article) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
36
37
38
39
40
# File 'app/helpers/magazine/application_helper.rb', line 33

def magazine_inside_public_period?(article)
  if article.started_at.present? && article.ended_at.present?
    today = Date.today
    article.started_at <= today && article.ended_at >= today
  else
    true
  end
end

#magazine_partial_path(name = nil, options = {}) ⇒ Object



14
15
16
17
18
19
# File 'app/helpers/magazine/application_helper.rb', line 14

def magazine_partial_path(name = nil, options = {})
  category = _magazine_val(:category, options)
  article = _magazine_val(:article, options)

  ['magazine', 'articles', 'shared', category.try(:category_slug), article.try(:slug), name].compact.join('/')
end

#respond_to?(method) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
45
46
47
48
49
50
51
52
# File 'app/helpers/magazine/application_helper.rb', line 42

def respond_to?(method)
  if method.to_s.end_with?('_path') or method.to_s.end_with?('_url')
    if main_app.respond_to?(method)
      true
    else
      super
    end
  else
    super
  end
end