Class: HtmlMockup::Release::Processors::Mockup

Inherits:
Base
  • Object
show all
Defined in:
lib/html_mockup/release/processors/mockup.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Mockup

Returns a new instance of Mockup.



6
7
8
9
10
11
12
13
14
# File 'lib/html_mockup/release/processors/mockup.rb', line 6

def initialize(options={})
  @options = {
    :env => {},
    :match => ["**/*.{html,md,html.erb}"],
    :skip => [/\Astylesheets/, /\Ajavascripts/]
  }
  
  @options.update(options) if options            
end

Instance Attribute Details

#projectObject

Returns the value of attribute project.



4
5
6
# File 'lib/html_mockup/release/processors/mockup.rb', line 4

def project
  @project
end

Instance Method Details

#call(release, options = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/html_mockup/release/processors/mockup.rb', line 16

def call(release, options={})
  self.project = release.project
  
  options = {}.update(@options).update(options)
  
  options[:env].update("MOCKUP_PROJECT" => project)
  
  release.log(self, "Processing mockup files")
  
  release.get_files(options[:match], options[:skip]).each do |file_path|
    self.run_on_file!(file_path, @options[:env])
  end
end

#extract_source_from_file(file_path, env = {}) ⇒ Object

Runs the extractor on a single file and return processed source.



42
43
44
# File 'lib/html_mockup/release/processors/mockup.rb', line 42

def extract_source_from_file(file_path, env = {})
  HtmlMockup::Template.open(file_path, :partials_path => self.project.partial_path, :layouts_path => self.project.layouts_path).render(env.dup)
end

#run_on_file!(file_path, env = {}) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/html_mockup/release/processors/mockup.rb', line 31

def run_on_file!(file_path, env = {})
  template = HtmlMockup::Template.open(file_path, :partials_path => self.project.partial_path, :layouts_path => self.project.layouts_path)
  
  # Clean up source file
  FileUtils.rm(file_path)
  
  # Write out new file
  File.open(self.target_path(file_path, template),"w"){|f| f.write(template.render(env.dup)) }
end