Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
17 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,48 +1,9 @@ | |||
#library('hart'); | #library('hart'); | ||
|
|
||
#import('dart:io'); | |||
#import('parser.dart'); | #import('parser.dart'); | ||
|
|
||
class Hart { | class Hart { | ||
static compile(data, filepath) { | static parse(String data) { | ||
new File(filepath).open(FileMode.WRITE, (file){ | return new Parser(data).parsed; | ||
String className = camelize(file.name.split('/').last().split('.')[0]); | |||
file.writeStringSync(""" | |||
#library('template'); | |||
#source('../lib/utils.dart'); | |||
class ${className} { | |||
Map locals; | |||
${className}(this.locals); | |||
noSuchMethod(String name, List args) { | |||
if (locals === null) { | |||
locals = {}; | |||
} | |||
if (name.length > 4) { | |||
String prefix = name.substring(0, 4); | |||
String key = name.substring(4); | |||
if (prefix == "get:") { | |||
return locals[key]; | |||
} else if (prefix == "set:") { | |||
locals[key] = args[0]; | |||
} | |||
} | |||
} | |||
render () { | |||
return ''' | |||
${new Parser(data).parsed} | |||
'''; | |||
} | |||
} | |||
"""); | |||
}); | |||
} | |||
|
|||
static String camelize(String name) { | |||
return Strings.join(name.split(const RegExp(@'-|_')).map((part) => part[0].toUpperCase() + part.substring(1)), ''); | |||
} | } | ||
} | } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters