Class: Monet::Router
Constant Summary collapse
- TYPES =
[ :baseline, :capture, :thumbnail ]
Instance Method Summary collapse
- #capture_routes ⇒ Object
- #diff_dir(filename = "") ⇒ Object
- #diff_url(path) ⇒ Object
-
#initialize(config) ⇒ Router
constructor
A new instance of Router.
- #original_url(path) ⇒ Object
- #url_to_filepath(url, width = "*") ⇒ Object
Constructor Details
#initialize(config) ⇒ Router
Returns a new instance of Router.
10 11 12 |
# File 'lib/monet/router.rb', line 10 def initialize(config) @config = config end |
Instance Method Details
#capture_routes ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/monet/router.rb', line 42 def capture_routes urls = {} @config.map.paths.each do |path| url = "#{@config.base_url}#{path}".chomp("/") @config.dimensions.each do |width| urls[url] ||= [] urls[url] << url_to_filepath(url, width) end end urls end |
#diff_dir(filename = "") ⇒ Object
32 33 34 35 |
# File 'lib/monet/router.rb', line 32 def diff_dir(filename="") filename = filename.gsub(".png", "-diff.png") unless filename.empty? File.join(@config.baseline_dir, @config.site, filename).chomp("/") end |
#diff_url(path) ⇒ Object
37 38 39 40 |
# File 'lib/monet/router.rb', line 37 def diff_url(path) diff = basename diff_dir(path) image_url(@config.baseline_dir, diff) end |
#original_url(path) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/monet/router.rb', line 25 def original_url(path) url = path.split("/").last path = url.split('|')[1..-1].join("/").gsub(/-\d+\.png/, "") "#{@config.base_url}/#{path}" end |
#url_to_filepath(url, width = "*") ⇒ Object
55 56 57 58 59 |
# File 'lib/monet/router.rb', line 55 def url_to_filepath(url, width="*") uri = parse_uri(url) name = File.join @config.site, "#{@config.site}#{uri.path.gsub(/\//, '|')}" File.join @config.capture_dir, "#{name}-#{width}.png" end |