class JsSourcemap::Env
Attributes
domain[RW]
is_build_dir_private[RW]
manifest[RW]
mapping_dir[RW]
sourcemap_yml[RW]
sources_dir[RW]
Public Class Methods
new()
click to toggle source
# File lib/js-sourcemap/env.rb, line 9 def initialize self.sources_dir = rails_path "public#{Rails.application.config.assets.prefix}" self.sourcemap_yml = rails_path "config/sourcemap.yml" self.mapping_dir = rails_path "#{sourcemap_config.fetch "mapping_directory"}#{Rails.application.config.assets.prefix}" self.domain = sourcemap_config.fetch "domain" self.manifest = get_manifest_file end
Public Instance Methods
build_absolute_path(path)
click to toggle source
# File lib/js-sourcemap/env.rb, line 57 def build_absolute_path(path) path = path.gsub(/.*(#{self.sources_dir}\/|#{self.mapping_dir}\/)/,'') path = "#{Rails.application.config.assets.prefix}/#{path}" "#{self.domain}#{path}" end
config_path()
click to toggle source
# File lib/js-sourcemap/env.rb, line 21 def config_path @config_path ||= Pathname.new(self.sourcemap_yml) end
get_manifest_file()
click to toggle source
# File lib/js-sourcemap/env.rb, line 45 def get_manifest_file return @manifest_hash if @manifest_hash files = Dir[File.join(self.sources_dir,"manifest*")] if files and files.length == 1 file = File.read(files.first) @manifest_hash = JSON.parse(file)["files"] else puts "Either none or more than one minifest file exists" end end
load_config()
click to toggle source
# File lib/js-sourcemap/env.rb, line 29 def load_config return {} if not readable? File.open config_path do |f| YAML.load f.read end end
rails_path(path)
click to toggle source
# File lib/js-sourcemap/env.rb, line 41 def rails_path(path) "#{Rails.root}/#{path}" end
readable?()
click to toggle source
# File lib/js-sourcemap/env.rb, line 25 def readable? config_path.readable? end
relative_path(path)
click to toggle source
# File lib/js-sourcemap/env.rb, line 36 def relative_path(path) dir = File.dirname(__FILE__) File.expand_path path, dir end
sourcemap_config()
click to toggle source
# File lib/js-sourcemap/env.rb, line 17 def sourcemap_config @sourcemap_config ||= load_config end