Class: Geostats::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/geostats/generator.rb

Constant Summary collapse

PARTS =
%w(difficulty_terrain_matrix milestones monthly_founds
founds_by_cache_type)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGenerator

Returns a new instance of Generator.



16
17
18
19
20
21
22
# File 'lib/geostats/generator.rb', line 16

def initialize
  @view = Views::Default.new
  @css = CssParser::Parser.new

  file = File.join(File.dirname(__FILE__), "templates", "stylesheet.css")
  @css.add_block!(File.read(file))
end

Class Method Details

.generateObject



12
13
14
# File 'lib/geostats/generator.rb', line 12

def self.generate
  new.generate
end

Instance Method Details

#generateObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/geostats/generator.rb', line 24

def generate
  PARTS.each do |part|
    require "geostats/views/#{part}"
    @view[part.to_sym] = "Geostats::Views::#{part.camelcase}".constantize.render
  end

  @doc = Hpricot(@view.render)

  @css.each_selector do |selector, style|
    @doc.search(selector) do |el|
      if el.elem?
        el["style"] = "#{el.attributes['style']} #{style}".strip
      end
    end
  end

  @doc.to_html
end