diff --git a/README.md b/README.md
index 56cbe9f..67d1012 100644
--- a/README.md
+++ b/README.md
@@ -34,53 +34,10 @@ main() {
article text here
and here
''';
- Hart.compile(template, 'template.dart');
+ print(Hart.parse(template));
}
```
-then use them in your code.
-
-``` dart
-#import('template.dart'); // import generated template
-
-main() {
- print(
- new Template({ // initialize template with local variables
- 'title': 'TITLETITLETITLE',
- 'newClass': 'newClass',
- 'items': [1,2,3]
- }).render()
- );
-}
-```
-
-This will generate
-
-``` html
-
-
-
-TITLETITLETITLE
-
-
-
-Welcome
-
-
-article text hereand here
-```
-
## License
(The MIT License)
diff --git a/bin/hart b/bin/hart
deleted file mode 100755
index b8f07c3..0000000
--- a/bin/hart
+++ /dev/null
@@ -1,27 +0,0 @@
-#!/usr/bin/env dart
-
-#import('dart:io');
-#import('../lib/hart.dart');
-
-compile(files) {
- new Directory('./gen').create((){});
- files.forEach((filepath) {
- var file = new File(filepath);
- file.readAsText(Encoding.UTF_8, (data) {
- Hart.compile(data, './gen/' + file.name.split('.')[0] + '.dart');
- });
- });
-}
-
-main(){
- List argv = new Options().arguments;
- String command = argv[0];
- List params = argv.getRange(1, argv.length - 1);
- switch(argv[0]) {
- case 'compile':
- compile(params);
- break;
- default:
- break;
- }
-}
\ No newline at end of file
diff --git a/template.haml b/hart.dart
old mode 100644
new mode 100755
similarity index 80%
rename from template.haml
rename to hart.dart
index 6a81cf4..6a22f3f
--- a/template.haml
+++ b/hart.dart
@@ -1,3 +1,8 @@
+#import('dart:io');
+#import('lib/hart.dart');
+
+main(){
+ print(Hart.parse('''
!!! 5
%html
%head
@@ -21,4 +26,6 @@
%li= item
%div.article.first
article text here
- and here
\ No newline at end of file
+ and here
+'''));
+}
\ No newline at end of file
diff --git a/lib/hart.dart b/lib/hart.dart
index e6bd2e2..81e8199 100644
--- a/lib/hart.dart
+++ b/lib/hart.dart
@@ -1,48 +1,9 @@
#library('hart');
-#import('dart:io');
#import('parser.dart');
class Hart {
- static compile(data, filepath) {
- new File(filepath).open(FileMode.WRITE, (file){
- 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)), '');
+ static parse(String data) {
+ return new Parser(data).parsed;
}
}
diff --git a/lib/parser.dart b/lib/parser.dart
index 616bd33..edd28d8 100644
--- a/lib/parser.dart
+++ b/lib/parser.dart
@@ -83,9 +83,10 @@ class Parser {
classes.add(next['val']);
break;
case 'attrs':
- const RegExp(@'(\w+) *:', ignoreCase:true).allMatches(next['val']).forEach((match){
+ Iterable matches = const RegExp(@'(\w+) *:', ignoreCase:true).allMatches(next['val']);
+ for (Match match in matches) {
buff.add(current['val'].replaceAll(match[1], "'${match[1]}'"));
- });
+ }
}
}
if (classes.length > 0) {
@@ -226,4 +227,4 @@ class Parser {
}
return buff.toString();
}
-}
+}
\ No newline at end of file
diff --git a/lib/utils.dart b/lib/utils.dart
index 74fda62..36e8190 100644
--- a/lib/utils.dart
+++ b/lib/utils.dart
@@ -1,3 +1,5 @@
+#library('utils');
+
class Filters {
static plain (str) => str;
static cdata (str) => '';