Class: Opal::Fragment
Overview
A fragment holds a string of generated javascript that will be written to the destination. It also keeps hold of the original sexp from which it was generated. Using this sexp, when writing fragments in order, a mapping can be created of the original location => target location, aka, source-maps!
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
String of javascript this fragment holds.
Instance Method Summary collapse
- #column ⇒ Object
-
#initialize(code, sexp = nil) ⇒ Fragment
constructor
A new instance of Fragment.
-
#inspect ⇒ Object
inspect the contents of this fragment, f("fooo").
- #line ⇒ Object
-
#to_code ⇒ Object
In debug mode we may wish to include the original line as a comment.
Constructor Details
#initialize(code, sexp = nil) ⇒ Fragment
Returns a new instance of Fragment
11 12 13 14 |
# File 'opal/lib/opal/fragment.rb', line 11 def initialize(code, sexp = nil) @code = code.to_s @sexp = sexp end |
Instance Attribute Details
#code ⇒ Object (readonly)
String of javascript this fragment holds
9 10 11 |
# File 'opal/lib/opal/fragment.rb', line 9 def code @code end |
Instance Method Details
#column ⇒ Object
37 38 39 |
# File 'opal/lib/opal/fragment.rb', line 37 def column @sexp.column if @sexp end |
#inspect ⇒ Object
inspect the contents of this fragment, f("fooo")
29 30 31 |
# File 'opal/lib/opal/fragment.rb', line 29 def inspect "f(#{@code.inspect})" end |
#line ⇒ Object
33 34 35 |
# File 'opal/lib/opal/fragment.rb', line 33 def line @sexp.line if @sexp end |
#to_code ⇒ Object
In debug mode we may wish to include the original line as a comment
17 18 19 20 21 22 23 |
# File 'opal/lib/opal/fragment.rb', line 17 def to_code if @sexp "/*:#{@sexp.line}:#{@sexp.column}*/#{@code}" else @code end end |