Class: Embarista::Filters::ManifestUrlFilter
- Inherits:
-
Rake::Pipeline::Filter
- Object
- Rake::Pipeline::Filter
- Embarista::Filters::ManifestUrlFilter
- Defined in:
- lib/embarista/filters/manifest_url_filter.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
- #urls_manifest ⇒ Object
Instance Method Summary collapse
- #generate_output(inputs, output) ⇒ Object
-
#initialize(options = {}, &block) ⇒ ManifestUrlFilter
constructor
A new instance of ManifestUrlFilter.
Constructor Details
#initialize(options = {}, &block) ⇒ ManifestUrlFilter
Returns a new instance of ManifestUrlFilter.
6 7 8 9 10 |
# File 'lib/embarista/filters/manifest_url_filter.rb', line 6 def initialize(= {}, &block) @options = || {} raise 'Must pass :path option' unless @options.key?(:path) super(&block) end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/embarista/filters/manifest_url_filter.rb', line 4 def @options end |
#urls_manifest ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/embarista/filters/manifest_url_filter.rb', line 13 def urls_manifest @urls_manifest ||= begin if File.exists?([:path]) JSON.parse(IO.read([:path])) else {} end end end |
Instance Method Details
#generate_output(inputs, output) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/embarista/filters/manifest_url_filter.rb', line 23 def generate_output(inputs, output) inputs.each do |input| code = input.read code.gsub!(%r{\bmanifest_url\(\s*(["'/])([^"']+)\1\)}) do |m| quote_char = $1 path = $2 # take the anchor/querystring off if there is one post_path_start = path.index(/[?#]/) if post_path_start post_path = path[post_path_start..-1] path = path[0..post_path_start-1] end path = "/#{path}" unless path =~ %r{^/} path = "#{[:prefix]}#{path}" resolved_path = urls_manifest[path] || path # put the anchor/querystring back on, if there is one resolved_path = resolved_path + post_path if post_path "(#{[:prepend]}'#{resolved_path}')" end output.write(code) end end |