Class: SourceMap
- Inherits:
-
Object
- Object
- SourceMap
- Defined in:
- lib/source_map.rb,
lib/source_map/vlq.rb,
lib/source_map/parser.rb,
lib/source_map/generator.rb
Defined Under Namespace
Modules: Generator, Parser, VLQ Classes: ParserError
Instance Attribute Summary collapse
-
#file ⇒ Object
The name of the file containing the code that this SourceMap describes.
-
#mappings ⇒ Object
A list of mapping objects.
-
#names ⇒ Object
A list of names (used during parsing/generating) (default []).
-
#source_root ⇒ Object
The URL/directory that contains the original source files.
-
#sources ⇒ Object
The list of sources (used during parsing/generating) These are relative to the source_root.
-
#version ⇒ Object
The version of the SourceMap spec we’re using.
Attributes included from Generator
Class Method Summary collapse
-
.from_json(json) ⇒ Object
Load a SourceMap from a Hash such as might be returned by Generator#as_json.
-
.from_s(str) ⇒ Object
Load a SourceMap from a String.
-
.load(filename) ⇒ Object
Load a SourceMap from a file.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ SourceMap
constructor
Create a new blank SourceMap.
Methods included from Parser
#parse_mapping, #parse_mappings, #undiff
Methods included from Generator
#add_generated, #add_mapping, #as_json, #save, #to_s
Constructor Details
#initialize(opts = {}) ⇒ SourceMap
Create a new blank SourceMap
Options may include:
:file => String # See #file :source_root => String # See #source_root :generated_output => IO # See SourceMap::Generator#generated_output
:sources => Array # See #sources :names => Array # See #names
:version => 3 # Which version of SourceMap to use (only 3 is allowed)
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/source_map.rb', line 25 def initialize(opts={}) unless (remain = opts.keys - [:generated_output, :file, :source_root, :sources, :names, :version]).empty? raise ArgumentError, "Unsupported options to SourceMap.new: #{remain.inspect}" end self.generated_output = opts[:generated_output] self.file = opts[:file] || '' self.source_root = opts[:source_root] || '' self.version = opts[:version] || 3 self.sources = opts[:sources] || [] self.names = opts[:names] || [] self.mappings = [] raise "version #{opts[:version]} not supported" if version != 3 end |
Instance Attribute Details
#file ⇒ Object
The name of the file containing the code that this SourceMap describes. (default “”)
41 42 43 |
# File 'lib/source_map.rb', line 41 def file @file end |
#mappings ⇒ Object
A list of mapping objects.
63 64 65 |
# File 'lib/source_map.rb', line 63 def mappings @mappings end |
#names ⇒ Object
A list of names (used during parsing/generating) (default [])
60 61 62 |
# File 'lib/source_map.rb', line 60 def names @names end |
#source_root ⇒ Object
The URL/directory that contains the original source files.
This is prefixed to the entries in [‘sources’] (default “”)
47 48 49 |
# File 'lib/source_map.rb', line 47 def source_root @source_root end |
#sources ⇒ Object
The list of sources (used during parsing/generating) These are relative to the source_root. (default [])
56 57 58 |
# File 'lib/source_map.rb', line 56 def sources @sources end |
#version ⇒ Object
The version of the SourceMap spec we’re using. (default 3)
51 52 53 |
# File 'lib/source_map.rb', line 51 def version @version end |
Class Method Details
.from_json(json) ⇒ Object
Load a SourceMap from a Hash such as might be returned by SourceMap::Generator#as_json.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/source_map/parser.rb', line 8 def self.from_json(json) raise ParserError, "Cannot parse version: #{json['version']} of SourceMap" unless json['version'] == 3 map = new(:file => json['file'], :source_root => json['sourceRoot'], :sources => json['sources'], :names => json['names']) map.parse_mappings(json['mappings'] || '') map end |
.from_s(str) ⇒ Object
Load a SourceMap from a String.
21 22 23 |
# File 'lib/source_map/parser.rb', line 21 def self.from_s(str) from_json JSON.parse(str) end |
.load(filename) ⇒ Object
Load a SourceMap from a file.
26 27 28 |
# File 'lib/source_map/parser.rb', line 26 def self.load(filename) from_s File.read(filename) end |