Class: JsSourcemap::Env
- Inherits:
-
Object
- Object
- JsSourcemap::Env
- Defined in:
- lib/js-sourcemap/env.rb
Instance Attribute Summary collapse
-
#domain ⇒ Object
Returns the value of attribute domain.
-
#is_build_dir_private ⇒ Object
Returns the value of attribute is_build_dir_private.
-
#manifest ⇒ Object
Returns the value of attribute manifest.
-
#mapping_dir ⇒ Object
Returns the value of attribute mapping_dir.
-
#sourcemap_yml ⇒ Object
Returns the value of attribute sourcemap_yml.
-
#sources_dir ⇒ Object
Returns the value of attribute sources_dir.
Instance Method Summary collapse
- #build_absolute_path(path) ⇒ Object
- #config_path ⇒ Object
- #get_manifest_file ⇒ Object
-
#initialize ⇒ Env
constructor
A new instance of Env.
- #load_config ⇒ Object
- #rails_path(path) ⇒ Object
- #readable? ⇒ Boolean
- #relative_path(path) ⇒ Object
- #sourcemap_config ⇒ Object
Constructor Details
#initialize ⇒ Env
Returns a new instance of Env.
9 10 11 12 13 14 15 |
# 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 |
Instance Attribute Details
#domain ⇒ Object
Returns the value of attribute domain.
6 7 8 |
# File 'lib/js-sourcemap/env.rb', line 6 def domain @domain end |
#is_build_dir_private ⇒ Object
Returns the value of attribute is_build_dir_private.
6 7 8 |
# File 'lib/js-sourcemap/env.rb', line 6 def is_build_dir_private @is_build_dir_private end |
#manifest ⇒ Object
Returns the value of attribute manifest.
6 7 8 |
# File 'lib/js-sourcemap/env.rb', line 6 def manifest @manifest end |
#mapping_dir ⇒ Object
Returns the value of attribute mapping_dir.
6 7 8 |
# File 'lib/js-sourcemap/env.rb', line 6 def mapping_dir @mapping_dir end |
#sourcemap_yml ⇒ Object
Returns the value of attribute sourcemap_yml.
6 7 8 |
# File 'lib/js-sourcemap/env.rb', line 6 def sourcemap_yml @sourcemap_yml end |
#sources_dir ⇒ Object
Returns the value of attribute sources_dir.
6 7 8 |
# File 'lib/js-sourcemap/env.rb', line 6 def sources_dir @sources_dir end |
Instance Method Details
#build_absolute_path(path) ⇒ Object
57 58 59 60 61 |
# 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 ⇒ Object
21 22 23 |
# File 'lib/js-sourcemap/env.rb', line 21 def config_path @config_path ||= Pathname.new(self.sourcemap_yml) end |
#get_manifest_file ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# 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 ⇒ Object
29 30 31 32 33 34 |
# 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) ⇒ Object
41 42 43 |
# File 'lib/js-sourcemap/env.rb', line 41 def rails_path(path) "#{Rails.root}/#{path}" end |
#readable? ⇒ Boolean
25 26 27 |
# File 'lib/js-sourcemap/env.rb', line 25 def readable? config_path.readable? end |
#relative_path(path) ⇒ Object
36 37 38 39 |
# File 'lib/js-sourcemap/env.rb', line 36 def relative_path(path) dir = File.dirname(__FILE__) File. path, dir end |
#sourcemap_config ⇒ Object
17 18 19 |
# File 'lib/js-sourcemap/env.rb', line 17 def sourcemap_config @sourcemap_config ||= load_config end |