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
29
30
31
32
33
34
# 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.log(self, "  Matching: #{options[:match].inspect}", true)      
  release.log(self, "  Skiping : #{options[:skip].inspect}", true)            
  release.log(self, "  Env     : #{options[:env].inspect}", true)
  release.log(self, "  Files   :", true)
  
  release.get_files(options[:match], options[:skip]).each do |file_path|
    release.log(self, "    Extract: #{file_path}", true)
    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.



48
49
50
# File 'lib/html_mockup/release/processors/mockup.rb', line 48

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



37
38
39
40
41
42
43
44
45
# File 'lib/html_mockup/release/processors/mockup.rb', line 37

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