Class: DOMCompiler
Overview
Pseudo-abstract inherited by all classes doing dom manipulations
Direct Known Subclasses
Constant Summary
Constants included from SqweezeUtils
SqweezeUtils::EMBED_MIME_TYPES
Instance Attribute Summary collapse
-
#dom_documents ⇒ Object
readonly
Returns the value of attribute dom_documents.
Instance Method Summary collapse
-
#css_cdata(text, callback) ⇒ Object
Wraps a string into CDATA escaped in order to be embedded into a
<style>
element. -
#get_resource(path_or_url) ⇒ Object
Retrieves a resource, being this either a URL or a file.
-
#initialize ⇒ DOMCompiler
constructor
A new instance of DOMCompiler.
-
#iterate_over(selector) ⇒ Object
Iterates over a DOM element and allows to apply a custom block over it.
-
#js_cdata(text, callback) ⇒ Object
Wraps a string into CDATA escaped in order to be embedded into a
<script>
element.
Methods included from SqweezeUtils
#ansi_bold, #ansi_green, #ansi_nocolour, #ansi_red, #ansi_yellow, #byteweight, #compression_percentage, #encoded_contents, #find_file_in_targetdir, #mime_type, #notify, #remap_filepath, #write_file
Constructor Details
#initialize ⇒ DOMCompiler
Returns a new instance of DOMCompiler.
6 7 8 9 10 11 |
# File 'lib/domCompiler.rb', line 6 def initialize # @dom_extnames=['.html','.svg'] @cm=ConfManager.instance #if @cm.link_assets_to and not @cm.link_assets_to.empty? @dom_documents=@cm.get_conf(:dom_documents).to_a end |
Instance Attribute Details
#dom_documents ⇒ Object (readonly)
Returns the value of attribute dom_documents.
4 5 6 |
# File 'lib/domCompiler.rb', line 4 def dom_documents @dom_documents end |
Instance Method Details
#css_cdata(text, callback) ⇒ Object
Wraps a string into CDATA escaped in order to be embedded into a <style>
element.
- text
-
a text string
- callback
-
an instance method used to process the string (normally compile).
47 48 49 |
# File 'lib/domCompiler.rb', line 47 def css_cdata(text,callback) ["/* <![CDATA[ */", self.send(callback,text), "/* ]]> */\n"].join("\n") end |
#get_resource(path_or_url) ⇒ Object
Retrieves a resource, being this either a URL or a file.
13 14 15 16 |
# File 'lib/domCompiler.rb', line 13 def get_resource(path_or_url) f=open(remap_filepath(path_or_url)) (f.is_a? File)? f.read : f end |
#iterate_over(selector) ⇒ Object
Iterates over a DOM element and allows to apply a custom block over it.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/domCompiler.rb', line 19 def iterate_over(selector) @dom_documents.each do |path| doc=Hpricot(open(path)) if doc doc.search(selector).each do |element| #$log.debug.. yield(element, doc) # save document #write_file(doc.innerHTML, [@cm.target_dir, File.basename(path) ].join('/') ) write_file(doc.innerHTML, path ) end else notify("DOMCompiler cannot parse #{path}",:error) end end end |
#js_cdata(text, callback) ⇒ Object
Wraps a string into CDATA escaped in order to be embedded into a <script>
element.
- text
-
a text string
- callback
-
an instance method used to process the string (normally compile).
40 41 42 |
# File 'lib/domCompiler.rb', line 40 def js_cdata(text,callback) ["\n<!--//--><![CDATA[//><!--", self.send(callback,text), "//--><!]]>\n"].join("\n") end |