|
| 1 | +SassijTreeNode = function( newOptions ){ |
| 2 | + |
| 3 | + if( newOptions ){ |
| 4 | + this.options = newOptions; |
| 5 | + } else { |
| 6 | + this.options = { style: 'none' }; |
| 7 | + } |
| 8 | + this.style = this.options.style; |
| 9 | + this.line = function(){ |
| 10 | + |
| 11 | + } |
| 12 | + this.filename = function(){ |
| 13 | + |
| 14 | + } |
| 15 | +}; |
| 16 | + |
| 17 | +SassijTreeNode.attr( 'children', [] ); |
| 18 | + |
| 19 | +SassijTreeNode.method( 'addChild', function( child ){ |
| 20 | + if( error = this.isInvalidChild( child ) ) { |
| 21 | + throw( new SassijError( error, child.line ) ); |
| 22 | + } |
| 23 | + this.children.push( child ); |
| 24 | + return this; |
| 25 | +}); |
| 26 | + |
| 27 | +SassijTreeNode.method( 'lastChild', function() { |
| 28 | + return this.getChildren()[ this.getChildren().length - 1 ]; |
| 29 | +}); |
| 30 | + |
| 31 | +SassijTreeNode.method( 'toS', function() { |
| 32 | + result = ""; |
| 33 | + for( child in this.getChildren() ){ |
| 34 | + if( child.isType( AttrNode ) ){ |
| 35 | + throw( new SassijError( 'Attributes aren\'t allowed at the root of a document.', child.line ) ); |
| 36 | + } else { |
| 37 | + // result << "#{child.to_s(1)}" + (@style == :compressed ? '' : "\n") |
| 38 | + // need to add a @style indicator at some point |
| 39 | + result += child.toS( 1 ); |
| 40 | + } |
| 41 | + } |
| 42 | + // @style == :compressed ? result+"\n" : result[0...-1] |
| 43 | + return result; |
| 44 | +}); |
| 45 | + |
| 46 | + // This method should be overridden by subclasses to return an error message |
| 47 | + // if the given child node is invalid, |
| 48 | + // and false or nil otherwise. |
| 49 | +SassijTreeNode.method( 'isInvalidChild', function( child ){ |
| 50 | + return false; |
| 51 | +}); |
| 52 | + |
| 53 | + |
| 54 | +// def perform(environment) |
| 55 | +// _perform(environment) |
| 56 | +// rescue Sass::SyntaxError => e |
| 57 | +// e.sass_line ||= line |
| 58 | +// raise e |
| 59 | +// end |
| 60 | +// Casey says: I don't really know what this function pretends to do. |
| 61 | +// I think this is just a wrapper to catch errors on evaluating the node. |
| 62 | +SassijTreeNode.method( 'perform', function( environment ){ |
| 63 | + try{ |
| 64 | + _perform( environment ); |
| 65 | + } catch( error ) { |
| 66 | + throw( new SassijError( error, 'unknown' ) ); |
| 67 | + } |
| 68 | +}); |
| 69 | + |
| 70 | +// def _perform(environment) |
| 71 | +// node = dup |
| 72 | +// node.perform!(environment) |
| 73 | +// node |
| 74 | +// end |
| 75 | +SassijTreeNode.method( '_perform', function( environment ){ |
| 76 | + node = this.clone(); |
| 77 | + node.performBang( environment ); |
| 78 | + return node; |
| 79 | +}); |
| 80 | + |
| 81 | +// def perform!(environment) |
| 82 | +// self.children = perform_children(Environment.new(environment)) |
| 83 | +// end |
| 84 | +// This function actually evaluates the node, and then recurses to |
| 85 | +// the children for evaluation with performChildren(). |
| 86 | +SassijTreeNode.method( 'performBang', function( environment ){ |
| 87 | + this.setChildren( this.performChildren( new SassijEnvironment( environment ) ) ); |
| 88 | +}); |
| 89 | + |
| 90 | + |
| 91 | +// def perform_children(environment) |
| 92 | +// children.map {|c| c.perform(environment)}.flatten |
| 93 | +// end |
| 94 | +// Casey says: js function for flatten()? Not sure why that would ever be needed. |
| 95 | +SassijTreeNode.method( 'performChildren', function( environment ){ |
| 96 | + childrenMap = []; |
| 97 | + for( child in this.getChildren() ){ |
| 98 | + childrenMap.push( child.perform( environment ) ); |
| 99 | + } |
| 100 | + return childrenMap; |
| 101 | +}); |
| 102 | + |
| 103 | +// def interpolate(text, environment) |
| 104 | +// res = '' |
| 105 | +// rest = Haml::Shared.handle_interpolation text do |scan| |
| 106 | +// escapes = scan[2].size |
| 107 | +// res << scan.matched[0...-2 - escapes] |
| 108 | +// if escapes % 2 == 1 |
| 109 | +// res << "\\" * (escapes - 1) << '#{' |
| 110 | +// else |
| 111 | +// res << "\\" * [0, escapes - 1].max |
| 112 | +// res << Script::Parser.new(scan, line, scan.pos - scan.matchedsize, filename). |
| 113 | +// parse_interpolated.perform(environment).to_s |
| 114 | +// end |
| 115 | +// end |
| 116 | +// res + rest |
| 117 | +// end |
| 118 | + // From what I can tell, this function handles the escapes for ruby-style inline |
| 119 | + // string evaluation. We'll come back to this. |
| 120 | +// this.interpolate = function( text, environment ){ |
| 121 | +// res = ""; |
| 122 | +// scanner = new Shared.handle_interpolate( text ); |
| 123 | +// while( var scan = scanner.scan( /(.*?)(\\*)\#\{/ ) ){ |
| 124 | +// if escapes = |
| 125 | +// res += |
| 126 | +// |
| 127 | +// } |
| 128 | +// escapes = rest[2].length; |
| 129 | +// res += rest.matched[] |
| 130 | +// //something else goes here!!!!! |
| 131 | + |
| 132 | +// // Append the rest of the original string. |
| 133 | +// return res += scanner.getCurrent(); |
| 134 | +// } |
| 135 | + |
| 136 | +// CAN'T FIND THIS METHOD CALLED ANYWHERE |
| 137 | +// def balance(*args) |
| 138 | +// res = Haml::Shared.balance(*args) |
| 139 | +// return res if res |
| 140 | +// raise Sass::SyntaxError.new("Unbalanced brackets.", line) |
| 141 | +// end |
| 142 | +// this.balance( args ){ |
| 143 | +// if( res = HamlijShared.balance( args ) ){ |
| 144 | +// return res; |
| 145 | +// }; |
| 146 | +// throw( new SassijError( 'Unbalanced brackets.', 'unknown' ) ); |
| 147 | +// } |
| 148 | + |
0 commit comments