Permalink
Browse files

YARD added

  • Loading branch information...
pitr-ch committed May 9, 2011
1 parent 09d4d8b commit 639c281870f0b4ef232046c4b3379289de98ea01
Showing with 132 additions and 109 deletions.
  1. +3 −0 .gitignore
  2. +109 −108 README.md
  3. +20 −1 Rakefile
View
@@ -1,2 +1,5 @@
nbproject
.rake_tasks~
+pkg
+.yardoc
+yardoc
View
217 README.md
@@ -28,149 +28,150 @@ Experimental fast xhtml builder with rich syntax:
end
end
end.to_xhtml
+
#=>
- <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html>
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <title>a title</title>
- </head>
- <body>
- <div id="menu" class="left">
- <ul>
- <li>home</li>
- <li class="active">contacts</li>
- </ul>
- </div>
- <div id="content">
- <article id="article1">
- <h1>header</h1>
- <p class="centered">some text</p>
- <div class="like hide">like on
- <strong>Facebook</strong>
- </div>
- </article>
- </div>
- </body>
- </html>
+ #<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html>
+ #<html xmlns="http://www.w3.org/1999/xhtml">
+ # <head>
+ # <title>a title</title>
+ # </head>
+ # <body>
+ # <div id="menu" class="left">
+ # <ul>
+ # <li>home</li>
+ # <li class="active">contacts</li>
+ # </ul>
+ # </div>
+ # <div id="content">
+ # <article id="article1">
+ # <h1>header</h1>
+ # <p class="centered">some text</p>
+ # <div class="like hide">like on
+ # <strong>Facebook</strong>
+ # </div>
+ # </article>
+ # </div>
+ # </body>
+ #</html>
## Helpers
You can mix it directly to Builder's instance
- require 'active_support'
- require 'action_view'
+ require 'active_support'
+ require 'action_view'
- Hammer::FormatedBuilder.new.go_in do
- extend ActionView::Helpers::NumberHelper
- div number_with_precision(Math::PI, :precision => 4)
- end.to_xhtml # => <div>3.1416</div>
+ Hammer::FormatedBuilder.new.go_in do
+ extend ActionView::Helpers::NumberHelper
+ div number_with_precision(Math::PI, :precision => 4)
+ end.to_xhtml # => <div>3.1416</div>
or make your own Builder
- require 'active_support'
- require 'action_view'
+ require 'active_support'
+ require 'action_view'
- class MyBuilder < Hammer::FormatedBuilder
- include ActionView::Helpers::NumberHelper
- end
+ class MyBuilder < Hammer::FormatedBuilder
+ include ActionView::Helpers::NumberHelper
+ end
- MyBuilder.new.go_in do
- div number_with_precision(Math::PI, :precision => 4)
- end.to_xhtml # => <div>3.1416</div>
+ MyBuilder.new.go_in do
+ div number_with_precision(Math::PI, :precision => 4)
+ end.to_xhtml # => <div>3.1416</div>
## Extensibility
- class MyBuilder < Hammer::FormatedBuilder
+ class MyBuilder < Hammer::FormatedBuilder
- # define new method to all tags
- redefine_class :abstract_tag do
- def hide!
- self.class 'hidden'
+ # define new method to all tags
+ redefine_class :abstract_tag do
+ def hide!
+ self.class 'hidden'
+ end
end
- end
- # add pseudo tag
- define_tag_class :component, :div do
- class_eval <<-RUBYCODE, __FILE__, __LINE__
- def open(id, attributes = nil, &block)
- super(attributes, &nil).id(id).class('component')
- block ? with(&block) : self
- end
- RUBYCODE
+ # add pseudo tag
+ define_tag_class :component, :div do
+ class_eval <<-RUBYCODE, __FILE__, __LINE__
+ def open(id, attributes = nil, &block)
+ super(attributes, &nil).id(id).class('component')
+ block ? with(&block) : self
+ end
+ RUBYCODE
+ end
end
- end
- MyBuilder.new.go_in do
- div[:content].with do
- span.id('secret').class('left').hide!
- component('component-1') do
- strong 'something'
+ MyBuilder.new.go_in do
+ div[:content].with do
+ span.id('secret').class('left').hide!
+ component('component-1') do
+ strong 'something'
+ end
end
- end
- end.to_xhtml
+ end.to_xhtml
and result is
- <div id="content">
- <span id="secret" class="left hidden"></span>
- <div id="component-1" class="component">
- <strong>something</strong>
+ <div id="content">
+ <span id="secret" class="left hidden"></span>
+ <div id="component-1" class="component">
+ <strong>something</strong>
+ </div>
</div>
- </div>
## Benchmark
### Synthetic
- user system total real
- render 5.010000 0.000000 5.010000 ( 5.185034)
- render3 4.990000 0.020000 5.010000 ( 5.037699)
- HammerBuilder::Standard 5.620000 0.000000 5.620000 ( 5.643001)
- HammerBuilder::Formated 5.610000 0.010000 5.620000 ( 5.623096)
- erubis 8.040000 0.010000 8.050000 ( 8.139744)
- erubis-reuse 4.970000 0.000000 4.970000 ( 4.990626)
- fasterubis 8.060000 0.030000 8.090000 ( 8.096832)
- fasterubis-reuse 4.930000 0.010000 4.940000 ( 4.934972)
- tenjin 12.390000 0.270000 12.660000 ( 12.642816)
- tenjin-reuse 3.540000 0.000000 3.540000 ( 3.557388)
- erector 15.320000 0.010000 15.330000 ( 15.378344)
- markaby 20.750000 0.030000 20.780000 ( 21.371292)
- tagz 73.200000 0.140000 73.340000 ( 73.306450)
+ user system total real
+ render 5.010000 0.000000 5.010000 ( 5.185034)
+ render3 4.990000 0.020000 5.010000 ( 5.037699)
+ HammerBuilder::Standard 5.620000 0.000000 5.620000 ( 5.643001)
+ HammerBuilder::Formated 5.610000 0.010000 5.620000 ( 5.623096)
+ erubis 8.040000 0.010000 8.050000 ( 8.139744)
+ erubis-reuse 4.970000 0.000000 4.970000 ( 4.990626)
+ fasterubis 8.060000 0.030000 8.090000 ( 8.096832)
+ fasterubis-reuse 4.930000 0.010000 4.940000 ( 4.934972)
+ tenjin 12.390000 0.270000 12.660000 ( 12.642816)
+ tenjin-reuse 3.540000 0.000000 3.540000 ( 3.557388)
+ erector 15.320000 0.010000 15.330000 ( 15.378344)
+ markaby 20.750000 0.030000 20.780000 ( 21.371292)
+ tagz 73.200000 0.140000 73.340000 ( 73.306450)
### In Rails 3
- BenchTest#test_erubis_partials (3.34 sec warmup)
- wall_time: 3.56 sec
- memory: 0.00 KB
- objects: 0
- gc_runs: 15
- gc_time: 0.53 ms
- BenchTest#test_erubis_single (552 ms warmup)
- wall_time: 544 ms
- memory: 0.00 KB
- objects: 0
- gc_runs: 4
- gc_time: 0.12 ms
- BenchTest#test_hammer_builder (2.33 sec warmup)
- wall_time: 847 ms
- memory: 0.00 KB
- objects: 0
- gc_runs: 5
- gc_time: 0.17 ms
- BenchTest#test_tenjin_partial (942 ms warmup)
- wall_time: 1.21 sec
- memory: 0.00 KB
- objects: 0
- gc_runs: 7
- gc_time: 0.25 ms
- BenchTest#test_tenjin_single (531 ms warmup)
- wall_time: 532 ms
- memory: 0.00 KB
- objects: 0
- gc_runs: 6
- gc_time: 0.20 ms
+ BenchTest#test_erubis_partials (3.34 sec warmup)
+ wall_time: 3.56 sec
+ memory: 0.00 KB
+ objects: 0
+ gc_runs: 15
+ gc_time: 0.53 ms
+ BenchTest#test_erubis_single (552 ms warmup)
+ wall_time: 544 ms
+ memory: 0.00 KB
+ objects: 0
+ gc_runs: 4
+ gc_time: 0.12 ms
+ BenchTest#test_hammer_builder (2.33 sec warmup)
+ wall_time: 847 ms
+ memory: 0.00 KB
+ objects: 0
+ gc_runs: 5
+ gc_time: 0.17 ms
+ BenchTest#test_tenjin_partial (942 ms warmup)
+ wall_time: 1.21 sec
+ memory: 0.00 KB
+ objects: 0
+ gc_runs: 7
+ gc_time: 0.25 ms
+ BenchTest#test_tenjin_single (531 ms warmup)
+ wall_time: 532 ms
+ memory: 0.00 KB
+ objects: 0
+ gc_runs: 6
+ gc_time: 0.20 ms
### Conclusion
View
@@ -1,12 +1,31 @@
require 'rubygems'
require 'rake'
+begin
+ require 'yard'
+
+ options = %w[--protected --private --verbose --main=README.md]
+ output = "--output-dir=./yardoc/"
+ input = %w[./lib/**/*.rb - LICENSE README.md]
+ title = "--title=HammerBuilder"
+
+ YARD::Rake::YardocTask.new(:yard) do |yardoc|
+ yardoc.options.push(*options) << output << title
+ yardoc.files.push(*input)
+ end
+
+rescue LoadError
+ task :yardoc do
+ abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
+ end
+end
+
begin
require 'jeweler'
Jeweler::Tasks.new do |gem|
gem.name = "hammer_builder"
gem.summary = %Q{fast ruby xhtml5 builder}
-# gem.description = %Q{ruby component based state-full web framework}
+ # gem.description = %Q{ruby component based state-full web framework}
gem.email = "hammer.framework@gmail.com"
gem.homepage = "https://github.com/ruby-hammer/hammer-builder"
gem.authors = ["Petr Chalupa"]

0 comments on commit 639c281

Please sign in to comment.