Class: HldrProcessor
- Inherits:
-
Object
- Object
- HldrProcessor
- Defined in:
- lib/hldr/hldr_processor.rb
Class Method Summary collapse
-
.generate_cache ⇒ Object
creates a cache location.
-
.generate_config ⇒ Object
creates a new config file.
Instance Method Summary collapse
- #add_scaffolding ⇒ Object
-
#initialize(location, options) ⇒ HldrProcessor
constructor
A new instance of HldrProcessor.
- #inline_assets ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(location, options) ⇒ HldrProcessor
9 10 11 12 13 14 15 16 17 |
# File 'lib/hldr/hldr_processor.rb', line 9 def initialize(location, ) begin @doc = Nokogiri::HTML(open(location)) rescue puts "Could not open input file '#{location}'" exit(1) end = end |
Class Method Details
.generate_cache ⇒ Object
creates a cache location
77 78 79 |
# File 'lib/hldr/hldr_processor.rb', line 77 def HldrProcessor.generate_cache Dir::mkdir ".hldr" if !Dir::exist? ".hldr" end |
.generate_config ⇒ Object
creates a new config file
82 83 84 |
# File 'lib/hldr/hldr_processor.rb', line 82 def HldrProcessor.generate_config File::open ".hldrconfig", "w" if !File::exist? ".hldrconfig" end |
Instance Method Details
#add_scaffolding ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/hldr/hldr_processor.rb', line 31 def add_scaffolding hldr_config = YAML.load_file('.hldrconfig') hldr_config["scaffolding"].each do |resource| # if ends in .css or is a hash with value of css, add style if resource[-4..-1] == ".css" css_res = Nokogiri::XML::Node.new "style", @doc css_res.content = open(resource).read css_res[:type] = "text/css" head = @doc.at_css("html") head << css_res end end end |
#inline_assets ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/hldr/hldr_processor.rb', line 52 def inline_assets inliners = { :link => StyleInliner, :script => ScriptInliner } # inhibit embedding images if flag set if [:no_embed] inliners[:img] = ImageInliner end inliners.each do |tag, inliner| @doc.css(tag.to_s).each do |element| inliner::(element) end end end |
#to_s ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/hldr/hldr_processor.rb', line 19 def to_s ## add config file scaffolding add_scaffolding ## process inlining inline_assets return @doc.to_html end |