Class: HtmlMockup::Release::Processors::Mockup
- Defined in:
- lib/html_mockup/release/processors/mockup.rb
Instance Attribute Summary collapse
-
#project ⇒ Object
Returns the value of attribute project.
Instance Method Summary collapse
- #call(release, options = {}) ⇒ Object
-
#extract_source_from_file(file_path, env = {}) ⇒ Object
Runs the extractor on a single file and return processed source.
-
#initialize(options = {}) ⇒ Mockup
constructor
A new instance of Mockup.
- #run_on_file!(file_path, env = {}) ⇒ Object
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 = { :env => {}, :match => ["**/*.{html,md,html.erb}"], :skip => [/\Astylesheets/, /\Ajavascripts/] } @options.update() if end |
Instance Attribute Details
#project ⇒ Object
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, ={}) self.project = release.project = {}.update(@options).update() [:env].update("MOCKUP_PROJECT" => project) release.log(self, "Processing mockup files") release.log(self, " Matching: #{[:match].inspect}", true) release.log(self, " Skiping : #{[:skip].inspect}", true) release.log(self, " Env : #{[:env].inspect}", true) release.log(self, " Files :", true) release.get_files([:match], [:skip]).each do |file_path| release.log(self, " Extract: #{file_path}", true) self.run_on_file!(file_path, [: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 |