-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Experimenting with moving output to erb templates.
- Loading branch information
Showing
9 changed files
with
81 additions
and
41 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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module MicroTest | ||
module DefaultHelper | ||
|
||
def duration_color(duration) | ||
return :yellow if @context.duration <= 0.01 | ||
:red | ||
end | ||
|
||
end | ||
end |
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module MicroTest | ||
class Template | ||
include Color | ||
|
||
def self.view(name) | ||
@views ||= {} | ||
@views[name] ||= File.read(File.expand_path("../views/default/#{name}.txt.erb", __FILE__)) | ||
end | ||
|
||
def initialize(object, *helpers) | ||
@context = object | ||
helpers.each { |helper| extend helper } | ||
end | ||
|
||
def render(name) | ||
instance_eval do | ||
print ERB.new(self.class.view(name), nil, ">").result(binding) | ||
end | ||
end | ||
|
||
def partial(name, options={}) | ||
return render(name) if options[:collection].nil? | ||
options[:collection].each do |item| | ||
Template.new(item).render(name) | ||
end | ||
end | ||
|
||
end | ||
end |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<%= @context[:file_path] %>:<%= red @context[:line_num] %> | ||
------------------------------------------------------------- |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<%= send duration_color(@context.duration), @context.duration %> | ||
<%= red @context.desc %> | ||
<%= partial :_assert_fail, :collection => @context.failed_asserts %> |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<%= send duration_color(@context.duration), @context.duration %> | ||
<%= green @context.desc %> |
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