Class: Rack::ScriptStackerUtils::Stacker
- Inherits:
-
Object
- Object
- Rack::ScriptStackerUtils::Stacker
- Defined in:
- lib/rack/scriptstacker.rb
Instance Method Summary collapse
- #find_files(source_path, serve_path) ⇒ Object
-
#initialize(config) ⇒ Stacker
constructor
A new instance of Stacker.
- #replace_slot(chunk) ⇒ Object
- #tag_inject(chunk) ⇒ Object
Constructor Details
#initialize(config) ⇒ Stacker
Returns a new instance of Stacker.
193 194 195 196 197 198 199 200 |
# File 'lib/rack/scriptstacker.rb', line 193 def initialize config @template = config[:template] @glob = config[:glob] @slot = config[:slot] @inject_before_tag = config[:inject_before_tag] @files = [] end |
Instance Method Details
#find_files(source_path, serve_path) ⇒ Object
202 203 204 205 206 |
# File 'lib/rack/scriptstacker.rb', line 202 def find_files source_path, serve_path @files = @files + files_for(source_path).map do |filename| sprintf @template, serve_path + filename end end |
#replace_slot(chunk) ⇒ Object
220 221 222 223 224 |
# File 'lib/rack/scriptstacker.rb', line 220 def replace_slot chunk chunk.gsub /^(\s*)#{slot}/ do file_list($1).join "\n" end end |
#tag_inject(chunk) ⇒ Object
208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/rack/scriptstacker.rb', line 208 def tag_inject chunk lines = chunk.split "\n", -1 # this preserves any trailing newlines index = lines.find_index { |line| line.match @inject_before_tag } return if index.nil? indent = lines[index].match(/^\s*/).to_s ( lines[0...index] + file_list(indent + ' ') + lines[index..-1] ).join "\n" end |