Class: HtmlMockup::Extractor Deprecated
- Inherits:
-
Object
- Object
- HtmlMockup::Extractor
- Defined in:
- lib/html_mockup/extractor.rb
Overview
Deprecated.
Don’t use the extractor anymore, use release.use(:mockup, options) processor and release.use(:url_relativizer, options) processor
Instance Attribute Summary collapse
-
#project ⇒ Object
readonly
Returns the value of attribute project.
-
#target_path ⇒ Object
readonly
Returns the value of attribute target_path.
Instance Method Summary collapse
-
#extract_source_from_file(file_path, env = {}) ⇒ Object
Runs the extractor on a single file and return processed source.
-
#initialize(project, target_path, options = {}) ⇒ Extractor
constructor
A new instance of Extractor.
- #run! ⇒ Object
- #run_on_file!(file_path, env = {}) ⇒ Object
Constructor Details
#initialize(project, target_path, options = {}) ⇒ Extractor
Returns a new instance of Extractor.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/html_mockup/extractor.rb', line 19 def initialize(project, target_path, ={}) @project = project @target_path = Pathname.new(target_path) @resolver = Resolver.new(self.target_path) @options = { :url_attributes => %w{src href action}, :url_relativize => true, :env => {} } @options.update() if @options[:env].update("MOCKUP_PROJECT" => project) end |
Instance Attribute Details
#project ⇒ Object (readonly)
Returns the value of attribute project.
9 10 11 |
# File 'lib/html_mockup/extractor.rb', line 9 def project @project end |
#target_path ⇒ Object (readonly)
Returns the value of attribute target_path.
9 10 11 |
# File 'lib/html_mockup/extractor.rb', line 9 def target_path @target_path end |
Instance Method Details
#extract_source_from_file(file_path, env = {}) ⇒ Object
Runs the extractor on a single file and return processed source.
63 64 65 66 67 68 69 70 71 |
# File 'lib/html_mockup/extractor.rb', line 63 def extract_source_from_file(file_path, env = {}) source = HtmlMockup::Template.open(file_path, :partials_path => self.project.partial_path, :layouts_path => self.project.layouts_path).render(env.dup) if @options[:url_relativize] source = relativize_urls(source, file_path) end source end |
#run! ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/html_mockup/extractor.rb', line 36 def run! target_path = self.target_path source_path = self.project.html_path filter = "**/*.html" raise ArgumentError, "Target #{target_path} already exists, please choose a new directory to extract into" if target_path.exist? mkdir_p(target_path) target_path = target_path.realpath # Copy source to target first, we'll overwrite the templates later on. cp_r(source_path.children, target_path) Dir.chdir(source_path) do Dir.glob(filter).each do |file_path| self.run_on_file!(file_path, @options[:env]) end end end |
#run_on_file!(file_path, env = {}) ⇒ Object
57 58 59 60 |
# File 'lib/html_mockup/extractor.rb', line 57 def run_on_file!(file_path, env = {}) source = self.extract_source_from_file(file_path, env) File.open(target_path + file_path,"w"){|f| f.write(source) } end |