Class: JadeSerializer
- Inherits:
-
Object
- Object
- JadeSerializer
- Defined in:
- jade/jade_serializer.rb
Overview
The JadeSerializer is used in order to convert a JadeObject to a string. Once it has been serialized into a string it can be saved to a file or sent as text.
Formatting (with pretty printing):
<variableOne>: ‘<valueOne>’;
<variableTwo>: ‘<valueTwo>’;
Formatting (without pretty printing):
<variableOne>: ‘<valueOne>’; <variableTwo>: ‘<valueTwo>’;
: -> Splits the variable and its value
; -> Denotes an end of line
‘ -> Surround the value of the variable
“ -> Can also surround the value of the variable
When parsing Jade ignores ALL whitespace, even in variables.
Instance Attribute Summary collapse
-
#:pretty_printing(: pretty_printing) ⇒ Object
The value of pretty printing is set outside of the class itself.
-
#pretty_printing ⇒ Object
The value of pretty printing is set outside of the class itself.
Instance Method Summary collapse
-
#initialize(pretty_printing = false) ⇒ NilClass
constructor
Initializes the value of pretty printing to false by default.
-
#make_str(args) ⇒ String
make_str takes args, this will be an array of JadePairs.
-
#to_file(jade_object, dir) ⇒ String
to_file converts a given JadeObject to a .jde file in a given directory.
-
#to_str(jade_object) ⇒ String
to_str converts a given JadeObject to a string.
Constructor Details
#initialize(pretty_printing = false) ⇒ NilClass
Initializes the value of pretty printing to false by default. This can be changed at runtime or set via the initializer.
48 49 50 |
# File 'jade/jade_serializer.rb', line 48 def initialize(pretty_printing = false) @pretty_printing = pretty_printing end |
Instance Attribute Details
#:pretty_printing(: pretty_printing) ⇒ Object
The value of pretty printing is set outside of the class itself.
40 |
# File 'jade/jade_serializer.rb', line 40 attr_accessor :pretty_printing |
#pretty_printing ⇒ Object
The value of pretty printing is set outside of the class itself.
40 41 42 |
# File 'jade/jade_serializer.rb', line 40 def pretty_printing @pretty_printing end |
Instance Method Details
#make_str(args) ⇒ String
make_str takes args, this will be an array of JadePairs. The array of JadePairs is then converted pair by pair into a string. The layout of the string may vary based on the whether pretty printing is on or not.
84 85 86 87 88 89 90 91 92 93 |
# File 'jade/jade_serializer.rb', line 84 def make_str(args) output = '' args.each_with_index do |arg, index| first, second = arg.to_array output += "#{first} : '#{second}';" output += "\n" if index != args.length - 1 && @pretty_printing end output.tr("\n", '') end |
#to_file(jade_object, dir) ⇒ String
to_file converts a given JadeObject to a .jde file in a given directory.
67 68 69 70 71 72 73 |
# File 'jade/jade_serializer.rb', line 67 def to_file(jade_object, dir) args = jade_object.args output = make_str(args) File.open(dir, 'w') File.write(dir, output) nil end |
#to_str(jade_object) ⇒ String
to_str converts a given JadeObject to a string.
57 58 59 60 |
# File 'jade/jade_serializer.rb', line 57 def to_str(jade_object) args = jade_object.args make_str(args) end |