Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
clean up, start structuring with temple assets.
- Loading branch information
Showing
4 changed files
with
95 additions
and
317 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,38 @@ | ||
## | ||
## an implementation of eRuby | ||
## | ||
## ex. | ||
## input = <<'END' | ||
## <ul> | ||
## <% for item in @list %> | ||
## <li><%= item %> | ||
## <%== item %></li> | ||
## <% end %> | ||
## </ul> | ||
## END | ||
## list = ['<aaa>', 'b&b', '"ccc"'] | ||
## eruby = Erubis::Eruby.new(input) | ||
## puts "--- code ---" | ||
## puts eruby.src | ||
## puts "--- result ---" | ||
## context = Erubis::Context.new() # or new(:list=>list) | ||
## context[:list] = list | ||
## puts eruby.evaluate(context) | ||
## | ||
## result: | ||
## --- source --- | ||
## _buf = ''; _buf << '<ul> | ||
## '; for item in @list | ||
## _buf << ' <li>'; _buf << ( item ).to_s; _buf << ' | ||
## '; _buf << ' '; _buf << Erubis::XmlHelper.escape_xml( item ); _buf << '</li> | ||
## '; end | ||
## _buf << '</ul> | ||
## '; | ||
## _buf.to_s | ||
## --- result --- | ||
## <ul> | ||
## <li><aaa> | ||
## <aaa></li> | ||
## <li>b&b | ||
## b&b</li> | ||
## <li>"ccc" | ||
## "ccc"</li> | ||
## </ul> | ||
## | ||
|
||
require "temple" | ||
require "erbse/parser" | ||
require "erbse/template" | ||
# require "erbse/eruby" | ||
|
||
module Erbse | ||
class BlockFilter < Temple::Filter | ||
# Highly inspired by https://github.com/slim-template/slim/blob/master/lib/slim/controls.rb#on_slim_output | ||
def on_erb_block(outter_i, inner_i, code, content_ast) | ||
# this is for <%= do %> | ||
outter_i = unique_name | ||
inner_i = unique_name | ||
|
||
# this still needs the Temple::Filters::ControlFlow run-through. | ||
[:multi, | ||
[:block, "#{outter_i} = #{code}", | ||
[:capture, inner_i, compile(content_ast)] # compile() is recursion on nested block content. | ||
], | ||
[:dynamic, outter_i] # return the outter buffer. # DISCUSS: why do we need that, again? | ||
] | ||
end | ||
end | ||
|
||
class Engine < Temple::Engine | ||
use Parser | ||
use BlockFilter | ||
|
||
# filter :MultiFlattener | ||
# filter :StaticMerger | ||
# filter :DynamicInliner | ||
filter :ControlFlow | ||
|
||
# Finally the generator | ||
generator :ArrayBuffer | ||
end | ||
|
||
end | ||
|
||
require "erbse/parser" | ||
require "erbse/template" | ||
require "erbse/eruby" |
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
Oops, something went wrong.