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
-
#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
#inspect ⇒ Object
inspect the contents of this fragment, f("fooo")
26 27 28 |
# File 'opal/lib/opal/fragment.rb', line 26 def inspect "f(#{@code.inspect})" end |
#line ⇒ Object
30 31 32 |
# File 'opal/lib/opal/fragment.rb', line 30 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}*/#{@code}" else @code end end |