Class: Pubba::Page

Inherits:
Object
  • Object
show all
Defined in:
lib/pubba/page.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, global_configuration = {}) ⇒ Page

Returns a new instance of Page.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/pubba/page.rb', line 6

def initialize(name, global_configuration = {})
  @name = name
  @assets = {"styles" => {}, "scripts" => {}}
  @head_tags = []
  @body_tags = []

  global_configuration["styles"].each do |key, value|
      @assets["styles"][key] = value.dup
  end

  script_groups do |group|
    @assets["scripts"][group] = global_configuration["scripts"][group] || []
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args) ⇒ Object



58
59
60
61
62
63
# File 'lib/pubba/page.rb', line 58

def method_missing(meth, *args)
  if Site.locale && (t = Site.locale.get(name, meth, *args))
    return t
  end
  super
end

Instance Attribute Details

#assetsObject (readonly)

Returns the value of attribute assets.



4
5
6
# File 'lib/pubba/page.rb', line 4

def assets
  @assets
end

#body_tagsObject (readonly)

Returns the value of attribute body_tags.



4
5
6
# File 'lib/pubba/page.rb', line 4

def body_tags
  @body_tags
end

#head_tagsObject (readonly)

Returns the value of attribute head_tags.



4
5
6
# File 'lib/pubba/page.rb', line 4

def head_tags
  @head_tags
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/pubba/page.rb', line 3

def name
  @name
end

Instance Method Details

#add_asset(type, section) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/pubba/page.rb', line 21

def add_asset(type, section)
  if type == "styles"
     section.each do |section_name, hash|
       hash.each do |key, value|
        if key == "urls"
          @assets[type][section_name][key] += value
        else
          @assets[type][section_name][key] = value
        end
      end
    end
  else
    script_groups do |group|
      @assets["scripts"][group] += section[group] if section[group]
    end
  end
end

#assetizeObject



39
40
41
42
# File 'lib/pubba/page.rb', line 39

def assetize
  create_style_assets
  create_script_assets
end

#tagifyObject



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/pubba/page.rb', line 44

def tagify
  style_groups do |group, hash|
    style_urls(group) do |url|
      add_style_tag(group, hash, url)
    end
  end

  script_groups do |group|
    script_urls(group) do |url|
      add_script_tag(group, url)
    end
  end
end