Remarkably 0.5.2 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,6 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
4
+ vendor/*
5
+ *.swp
6
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in remarkably.gemspec
4
+ gemspec
data/README ADDED
@@ -0,0 +1,89 @@
1
+ Remarkably can be used as template enginge generating HTML pages by
2
+ calling "pure" ruby methods, e.g.:
3
+ html do
4
+ header do
5
+ title "my header"
6
+ end
7
+ body do
8
+ h1 "big header"
9
+ ul do
10
+ (1..2).each do |n|
11
+ li "line #{n}"
12
+ end
13
+ end
14
+ end
15
+ end
16
+
17
+ This beautiful approach allows ruby control statements while generating
18
+ the desired page without the hassle other template engines have when
19
+ mixing HTML tags and ruby control.
20
+
21
+ A remarkably fact about Remarkably is, that is does not know anything
22
+ about HTML tags. It handles the generating of the desired page source by
23
+ using the ruby mechanism of the "method_missing" message: every(!) unkown
24
+ method will be recovered by generating appropriate HTML statements.
25
+
26
+ One of the consequences of approach is, that the parameters of such a "tag"
27
+ must follow some rules: it have to look like
28
+ sym(args, hash, &block)
29
+ that means, eventual arguments must be set before an eventual hash, which
30
+ sets the tag attributes, followed by an eventual block, which contains included
31
+ other tags.
32
+
33
+ Sounds terrible complicated, but it is not, e.g.: the ruby statement
34
+ a('Home', :href => "#{rs(:index)}")
35
+ will generate after the ruby interpolation
36
+ <a href="/index">Home</a>
37
+
38
+ To generate an anchor with a graphic icon like
39
+ <a href="/help" title="Help">
40
+ <img src="icons/help.png" border="0" alt="Help"/>
41
+ </a>
42
+ can be produced e.g. by
43
+ def gen_link(txt, href, icon)
44
+ a(:href => href, :title => txt) do
45
+ img(:src => icon, :border => 0, :alt => txt)
46
+ end # a
47
+ end # genlink
48
+ gen_link('Help', "#{rs(:help)}", 'icons/help.png')
49
+ You see, it is also possible to call methods when generating the page.
50
+
51
+ This shows another challenge: you can not generate a tag, which name
52
+ conflicts with a well known ruby method, e.g.:
53
+ p "this is some text"
54
+ will use the kernel method p to print the message to the console. To
55
+ generate a paragraph, you can use an upcase P like
56
+ P "this is another paragraph"
57
+ Dont worry, Remarkably uses .downcase when generating the code:
58
+ <p>this is another paragraph</p>
59
+ which keeps it XHTML conform.
60
+
61
+ The missing_method approach also has the consequence, that Reamrkably
62
+ can not check for valid HTML tags, e.g.:
63
+ xyz(:abc => "nonsens")
64
+ generates a syntatic correct, but semantic wrong output
65
+ <xyz abc="nonsens">
66
+ So check careful the page source offered from your browser.
67
+
68
+ There are at least two differences to Markaby: the "syntactic" sugar
69
+ for .class and .id! is not supported, e.g.:
70
+ div.myclass
71
+ must be edited to
72
+ div(:class => 'myclass')
73
+ and
74
+ div.myid!
75
+ must be edited to
76
+ div(:id => 'myid')
77
+
78
+ To insert some (eventual ruby interpolated) text in the page use text(), e.g.:
79
+ text("#{@content}")
80
+
81
+ To use Remarkably within Ramaze just set in your controller:
82
+ class Controller < Ramaze::Controller
83
+ helper :remarkably
84
+ engine :Remarkably
85
+ end # controller
86
+ and put your Remarkably files named *.rem into the view/ directory
87
+
88
+ To keep Ramaze happy, you should terminate your .rem files with the line:
89
+ remarkably_engine
@@ -0,0 +1,9 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+
6
+ desc "Run specs"
7
+ RSpec::Core::RakeTask.new do |t|
8
+ t.pattern = "./spec/**/*.rb"
9
+ end
@@ -0,0 +1,38 @@
1
+ require '../loadpath'
2
+ require 'remarkably/engines/css'
3
+ require 'remarkably/engines/css/helpers'
4
+
5
+ class Page
6
+ include Remarkably::Common
7
+
8
+ def style
9
+ body do
10
+ background_color :white
11
+ color :black
12
+
13
+ div( "#header" ) do
14
+ ul do
15
+ margin 0
16
+ padding 8.px, 2.px, 4.px, 1.5.em
17
+ li do
18
+ padding_left 2.em
19
+ end
20
+ end
21
+ end
22
+
23
+ P do
24
+ color :black
25
+ font_size 12.pt
26
+ end
27
+
28
+ P(".special") do
29
+ color :blue
30
+ end
31
+
32
+ end
33
+ end
34
+
35
+ end
36
+
37
+ page = Page.new
38
+ puts page.style.to_s
@@ -0,0 +1,95 @@
1
+ require '../loadpath'
2
+ require 'remarkably/engines/html'
3
+ require 'remarkably/engines/css/helpers'
4
+
5
+ class Site
6
+ include Remarkably::Common
7
+
8
+ def index
9
+ page do
10
+ P "Hello World!"
11
+ end
12
+ end
13
+
14
+ def exit
15
+ page do
16
+ P "Goodbye cruel world"
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ def page
23
+ html do
24
+ head do
25
+ title "A basic Remarkably HTML example"
26
+ style do
27
+ body {
28
+ margin 0
29
+ padding 0
30
+ font_size 12.pt
31
+ background_color :white
32
+ }
33
+ div("#header") {
34
+ margin 0
35
+ padding 0
36
+ background_color "#ffd"
37
+ border_bottom 1.px, :dashed, :black
38
+ h1 {
39
+ margin 0
40
+ padding 0, 0, 4.px, 0
41
+ text_align :center
42
+ font_size 24.pt
43
+ font_weight :normal
44
+ a {
45
+ color :black
46
+ }
47
+ }
48
+ }
49
+ div("#footer") {
50
+ text_align :right
51
+ font_size 9.pt
52
+ margin 16.px, 0, 0, 0
53
+ padding 0
54
+ border_top 1.px, :solid, :black
55
+ }
56
+ div("#content") {
57
+ margin 16.px
58
+ }
59
+ a {
60
+ color :blue
61
+ }
62
+ a(":hover") {
63
+ color :red
64
+ }
65
+ end
66
+ end
67
+ body do
68
+ div :id => "header" do
69
+ h1 do
70
+ text "A basic "
71
+ a "Remarkably", :href => "http://www.darkarts.co.za/project/remarkably"
72
+ text " HTML example"
73
+ end
74
+ end
75
+ div :id => "content" do
76
+ yield
77
+ end
78
+ div :id => "footer" do
79
+ text "This was a "
80
+ a "Remarkably", :href => "http://www.darkarts.co.za/project/remarkably"
81
+ text " example."
82
+ end
83
+ end
84
+ end
85
+ end
86
+
87
+ end
88
+
89
+ site = Site.new
90
+
91
+ puts "\n== Index Page ==\n"
92
+ puts site.index.to_s
93
+
94
+ puts "\n== Exit Page ==\n"
95
+ puts site.exit.to_s
@@ -0,0 +1,51 @@
1
+ require '../loadpath'
2
+ require 'remarkably/engines/xml'
3
+
4
+ class Products
5
+ include Remarkably::Common
6
+
7
+ def range
8
+ products do
9
+ (1...10).each do |product_number|
10
+ product :id => product_number do
11
+ colour %w{red green blue yellow black}[product_number%5]
12
+ description "This is the description for product No #{product_number}"
13
+ end
14
+ end
15
+ end
16
+ end
17
+
18
+ def range_page
19
+ html do
20
+ head do
21
+ title "Our product range"
22
+ end
23
+ body do
24
+ h1 "Our product range"
25
+ table do
26
+ tr do
27
+ th "Product ID"
28
+ th "Product Description"
29
+ th "Colour"
30
+ end
31
+ (1...10).each do |product_number|
32
+ tr do
33
+ td product_number
34
+ td "This is the description for product No #{product_number}"
35
+ td %w{red green blue yellow black}[product_number%5]
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ end
44
+
45
+ our_products = Products.new
46
+
47
+ puts "\n== Product Range ==\n"
48
+ puts our_products.range.to_s
49
+
50
+ puts "\n== Product Range web page ==\n"
51
+ puts our_products.range_page.to_s
@@ -0,0 +1,62 @@
1
+ require '../loadpath'
2
+ require 'remarkably/engines/html'
3
+ require 'remarkably/engines/html/helpers'
4
+
5
+ class Site
6
+ include Remarkably::Common
7
+
8
+ def index
9
+ html do
10
+ head do
11
+ title "A Remarkably bookmarklet example"
12
+ end
13
+ body do
14
+ h1 "The bookmarklet"
15
+ P do
16
+ text "Simply click \""
17
+ java_script = %w{h1 h2 h3 h4 p a}.inject('') do |result,tag|
18
+ result+= <<-EOS
19
+
20
+ tags = document.getElementsByTagName("#{tag}");
21
+ for (i=0;i<tags.length;i++) {
22
+ header_content = tags[i].innerHTML;
23
+ tags[i].innerHTML =
24
+ '<span style="border:1px solid black;color:black;background-color:#FFA">&lt;#{tag}&gt;</span>' + header_content +
25
+ '<span style="border:1px solid black;color:black;background-color:#FFA">&lt;/#{tag}&gt;</span>';
26
+ }
27
+
28
+ EOS
29
+ end
30
+ bookmarklet java_script, "Show some tags"
31
+ text "\", or drag it and drop it on your toolbar to use it on any site."
32
+ end
33
+ h1 "Header 1"
34
+ lorum_ipsum
35
+ h2 "Header 2"
36
+ lorum_ipsum
37
+ h3 "Header 3"
38
+ lorum_ipsum
39
+ h3 "Header 3"
40
+ lorum_ipsum
41
+ h2 "Header 2"
42
+ lorum_ipsum
43
+ h3 "Header 3"
44
+ lorum_ipsum
45
+ h1 "Header 1"
46
+ lorum_ipsum
47
+ h2 "Header 2"
48
+ end
49
+ end
50
+ end
51
+
52
+ private
53
+
54
+ def lorum_ipsum
55
+ P <<-EOS
56
+ Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Vestibulum vehicula lectus vitae sapien. Nam quis lorem id velit tempor convallis. Nullam est orci, placerat a, hendrerit rutrum, dictum quis, magna. Nulla pharetra libero ac risus. Fusce in elit. Cras vel nisl nec enim tincidunt vehicula. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Praesent sollicitudin, libero sit amet hendrerit fermentum, odio nisl mollis enim, quis faucibus nisi nisi eu erat. Vivamus eu urna at velit mattis congue. Morbi feugiat erat vel libero.
57
+ EOS
58
+ end
59
+
60
+ end
61
+
62
+ puts Site.new.index.to_s
@@ -0,0 +1,38 @@
1
+ require '../loadpath'
2
+ require 'remarkably/engines/html'
3
+
4
+ class Page
5
+ include Remarkably::Common
6
+
7
+ def header
8
+ h1 "A Header and Footer example with Remarkably"
9
+ hr
10
+ end
11
+
12
+ def footer
13
+ hr
14
+ text "Find out more about Remarkably "
15
+ a "here", :href=>"http://www.darkarts.co.za"
16
+ text "."
17
+ end
18
+
19
+ def entire_page
20
+ html do
21
+ head do
22
+ title "Remarkably: Headers and Footers"
23
+ end
24
+ body do
25
+ header
26
+ P "This is some page content"
27
+ footer
28
+ end
29
+ end
30
+ end
31
+
32
+ end
33
+
34
+ page = Page.new
35
+
36
+ puts "Just the header => #{page.header}"
37
+ puts "Just the footer => #{page.footer}"
38
+ puts "The entire page => #{page.entire_page}"
@@ -0,0 +1,54 @@
1
+ require '../loadpath'
2
+ require 'remarkably/engines/html'
3
+
4
+ class Page
5
+ include Remarkably::Common
6
+
7
+ def main_page
8
+ page do
9
+ P "Hello World!"
10
+ end
11
+ end
12
+
13
+ def exit_page
14
+ page do
15
+ P "Goodbye World!"
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def menu
22
+ div :id=>"menu" do
23
+ ul do
24
+ li 'foo'
25
+ li 'bar'
26
+ li 'baz'
27
+ end
28
+ end
29
+ end
30
+
31
+ def footer
32
+ div "This is a footer", :id=>"footer"
33
+ end
34
+
35
+ def page
36
+ html do
37
+ head do
38
+ title "Test Page"
39
+ end
40
+ body do
41
+ menu
42
+ div :id => "content" do
43
+ yield
44
+ end
45
+ footer
46
+ end
47
+ end
48
+ end
49
+
50
+ end
51
+
52
+ page = Page.new
53
+ puts "Main Page => #{page.main_page}"
54
+ puts "Exit Page => #{page.exit_page}"
@@ -1,3 +1,5 @@
1
+ require 'remarkably/version'
2
+
1
3
  module Remarkably
2
4
 
3
5
  module Config
@@ -9,16 +11,22 @@ module Remarkably
9
11
  module Base
10
12
 
11
13
  class Engine
14
+
15
+ attr_reader :remarkably_engine
16
+
12
17
  def initialize *args, &block
13
18
  clear!
19
+ @remarkably_engine = self
14
20
  self.instance_eval( &block ) if block_given?
15
21
  end
16
22
 
17
23
  def missing_method(sym, context, *args, &block)
18
24
  @context = context
19
25
  hash = args.last.is_a?(Hash) ? args.pop : {}
20
- if methods.index( sym.to_s )
21
- self.send( sym, args, hash, &block )
26
+ responder ||= context.remarkably_engine if context.remarkably_engine.respond_to?( sym )
27
+ responder ||= self if self.respond_to?( sym )
28
+ if responder
29
+ responder.send( sym, args, hash, &block )
22
30
  else
23
31
  method!(sym, args, hash, &block)
24
32
  end
@@ -9,7 +9,7 @@ end
9
9
  class Array
10
10
  def css *args, &block
11
11
  self.each do |item|
12
- eval( 'self', block ).send( item.to_sym , *args, &(lambda { yield }) )
12
+ eval( 'self', block.binding ).send( item.to_sym , *args, &(lambda { yield }) )
13
13
  end
14
14
  end
15
15
  end
@@ -0,0 +1,19 @@
1
+ module Remarkably
2
+ module Engines
3
+ class HTML < XML
4
+ def bookmarklet args, hash, &block
5
+ inline_javascript = args.shift.split("\n").map{|l|l.strip}.join('')
6
+ inline_javascript.gsub!( '%', '%25' )
7
+ { "'" => "%27",
8
+ '"' => "%22",
9
+ '&' => "%26",
10
+ '/' => "%2F",
11
+ }.each_pair do |key,value|
12
+ inline_javascript.gsub!( key, value )
13
+ end
14
+ hash[:href]=%|javascript:(function(){#{inline_javascript}})();|
15
+ method!( :a, args, hash, &block )
16
+ end
17
+ end
18
+ end
19
+ end
@@ -10,7 +10,7 @@ module Remarkably
10
10
  tag_attributes =
11
11
  hash.inject([]){|s,(k,v)| s << %{#{k.to_s.downcase}="#{v}"} }
12
12
 
13
- @output << ["<#{sym}", tag_attributes].flatten.grep(/\S/).join(' ')
13
+ @output << ( ["<#{sym}"] + tag_attributes).join(' ')
14
14
 
15
15
  if block_given? or not args.empty?
16
16
  @output << ">"
@@ -23,7 +23,7 @@ module Remarkably
23
23
  self
24
24
  end
25
25
 
26
- def text args, hash, &block
26
+ def text args, hash
27
27
  @output << args.join
28
28
  self
29
29
  end
@@ -0,0 +1,3 @@
1
+ module Remarkably
2
+ VERSION = "0.6.0"
3
+ end
@@ -0,0 +1 @@
1
+ $:.unshift "#{File::dirname(__FILE__)}/lib/"
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "remarkably/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "Remarkably"
7
+ s.version = Remarkably::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Clive Crous"]
10
+ s.email = ["clive@crous.co.za"]
11
+ s.homepage = "http://www.darkarts.co.za/remarkably"
12
+ s.summary = %q{A very tiny Markaby-like XML,HTML and CSS builder}
13
+ s.description = %q{Remarkably is a very tiny Markaby-like XML,HTML and CSS builder}
14
+
15
+ s.add_development_dependency "bundler", ">= 1.0.0"
16
+ s.add_development_dependency "rake", ">= 0.8.7"
17
+ s.add_development_dependency "rspec", ">= 1.3.0"
18
+
19
+ s.files = `git ls-files`.split("\n")
20
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
+ s.require_paths = ["lib"]
23
+ end
@@ -0,0 +1,62 @@
1
+ require 'remarkably/engines/css'
2
+
3
+ describe Remarkably::Engines::CSS do
4
+ include Remarkably::Common
5
+
6
+ before( :all ) do
7
+ @remarkably_engine = Remarkably::Engines::CSS.new
8
+ end
9
+
10
+ it "Does basic styling" do
11
+ body do
12
+ P do
13
+ background_color :white
14
+ border "1px", :solid, :black
15
+ end
16
+ div do
17
+ color :blue
18
+ end
19
+ end.to_s.should == "body p {background-color:white;border:1px solid black}\nbody div {color:blue}\n"
20
+ end
21
+
22
+ it "uses css class" do
23
+ div do
24
+ css_class do
25
+ foo do
26
+ color :red
27
+ end
28
+ end
29
+ bar? do
30
+ color :blue
31
+ end
32
+ P do
33
+ color :green
34
+ end
35
+ end.to_s.should == "div .foo {color:red}\ndiv .bar {color:blue}\ndiv p {color:green}\n"
36
+ end
37
+
38
+ it "uses css id" do
39
+ div do
40
+ css_id do
41
+ foo do
42
+ color :red
43
+ end
44
+ bar do
45
+ color :blue
46
+ end
47
+ end
48
+ baz! do
49
+ color :green
50
+ end
51
+ end.to_s.should == "div #foo {color:red}\ndiv #bar {color:blue}\ndiv #baz {color:green}\n"
52
+ end
53
+
54
+ it "uses css pseudo" do
55
+ css_pseudo do
56
+ hover do
57
+ color :red
58
+ end
59
+ end.to_s.should == ":hover {color:red}\n"
60
+ end
61
+
62
+ end
@@ -0,0 +1,32 @@
1
+ require 'remarkably/engines/css'
2
+ require 'remarkably/engines/css/helpers'
3
+
4
+ describe "Remarkably::Engines::CSS Helpers" do
5
+ include Remarkably::Common
6
+
7
+ before( :all ) do
8
+ @remarkably_engine = Remarkably::Engines::CSS.new
9
+ end
10
+
11
+ it "Uses numbers correctly" do
12
+ body do
13
+ P do
14
+ background_color :white
15
+ border 1.px, :solid, :black
16
+ font_size 2.5.em
17
+ end
18
+ div do
19
+ color :blue
20
+ end
21
+ end.to_s.should == "body p {background-color:white;border:1px solid black;font-size:2.5em}\nbody div {color:blue}\n"
22
+ end
23
+
24
+ it "uses arrays" do
25
+ body do
26
+ %w{h1 h2 h3}.css do
27
+ color :blue
28
+ end
29
+ end.to_s.should == "body h1 {color:blue}\nbody h2 {color:blue}\nbody h3 {color:blue}\n"
30
+ end
31
+
32
+ end
@@ -0,0 +1,81 @@
1
+ require 'remarkably/engines/html'
2
+
3
+ describe "Remarkably::Engine::HTML instance_eval" do
4
+ it "performs an instance_eval when a block is given to new" do
5
+ Remarkably::Engines::HTML.new do
6
+ html do
7
+ body do
8
+ P "Hello World!"
9
+ end
10
+ end
11
+ end.to_s.should == "<html><body><p>Hello World!</p></body></html>"
12
+ end
13
+ end
14
+
15
+ describe Remarkably::Engines::HTML do
16
+ include Remarkably::Common
17
+
18
+ before( :all ) do
19
+ @remarkably_engine = Remarkably::Engines::HTML.new
20
+ end
21
+
22
+ it "Accepts a string as a paramater" do
23
+ testing( "Hello World" ).to_s.should ==
24
+ "<testing>Hello World</testing>"
25
+ end
26
+
27
+ it "Accepts a block as a paramater" do
28
+ testing do
29
+ text "Hello World"
30
+ end.to_s.should ==
31
+ "<testing>Hello World</testing>"
32
+ end
33
+
34
+ it "Accepts multiple strings as paramaters" do
35
+ testing( "Hello", "World" ).to_s.should ==
36
+ "<testing>HelloWorld</testing>"
37
+ end
38
+
39
+ it "Closes empty tags neatly" do
40
+ testing.to_s.should ==
41
+ "<testing/>"
42
+ end
43
+
44
+ it "Accepts only attributes" do
45
+ testing( :id => "attributes" ).to_s.should ==
46
+ '<testing id="attributes"/>'
47
+ end
48
+
49
+ it "Accepts strings and attributes" do
50
+ testing( "Hello ", "World",
51
+ :id => "attributes", :class => "test" ).to_s.should ==
52
+ '<testing id="attributes" class="test">Hello World</testing>'
53
+ end
54
+
55
+ it "Allows yielding for internal content" do
56
+ def page
57
+ html do
58
+ body do
59
+ yield
60
+ end
61
+ end
62
+ end
63
+
64
+ page do
65
+ P "Internal Content"
66
+ end.to_s.should == "<html><body><p>Internal Content</p></body></html>"
67
+ end
68
+
69
+ it "Does auto-style" do
70
+ html do
71
+ head do
72
+ style do
73
+ body do
74
+ color :blue
75
+ end
76
+ end
77
+ end
78
+ end.to_s.should == "<html><head><style>\nbody {color:blue}\n</style></head></html>"
79
+ end
80
+
81
+ end
@@ -0,0 +1,92 @@
1
+ require 'remarkably/engines/xml'
2
+
3
+ describe "Remarkably::Engine::XML explicit engine usage" do
4
+ it "performs an instance_eval when a block is given to new" do
5
+ xml = Remarkably::Engines::XML.new
6
+ xml.html do
7
+ xml.body do
8
+ xml.P "Hello World!"
9
+ end
10
+ end.to_s.should == "<html><body><p>Hello World!</p></body></html>"
11
+ end
12
+ end
13
+
14
+ describe "Remarkably::Engine::XML instance_eval" do
15
+ it "performs an instance_eval when a block is given to new" do
16
+ Remarkably::Engines::XML.new do
17
+ html do
18
+ body do
19
+ P "Hello World!"
20
+ end
21
+ end
22
+ end.to_s.should == "<html><body><p>Hello World!</p></body></html>"
23
+ end
24
+ end
25
+
26
+ describe Remarkably::Engines::XML do
27
+ include Remarkably::Common
28
+
29
+ before( :all ) do
30
+ @remarkably_engine = Remarkably::Engines::XML.new
31
+ end
32
+
33
+ it "Accepts a string as a paramater" do
34
+ testing( "Hello World" ).to_s.should ==
35
+ "<testing>Hello World</testing>"
36
+ end
37
+
38
+ it "Accepts a block as a paramater" do
39
+ testing do
40
+ text "Hello World"
41
+ end.to_s.should ==
42
+ "<testing>Hello World</testing>"
43
+ end
44
+
45
+ it "Accepts multiple strings as paramaters" do
46
+ testing( "Hello", "World" ).to_s.should ==
47
+ "<testing>HelloWorld</testing>"
48
+ end
49
+
50
+ it "Closes empty tags neatly" do
51
+ testing.to_s.should ==
52
+ "<testing/>"
53
+ end
54
+
55
+ it "Accepts only attributes" do
56
+ testing( :id => "attributes" ).to_s.should ==
57
+ '<testing id="attributes"/>'
58
+ end
59
+
60
+ it "Accepts strings and attributes" do
61
+ testing( "Hello ", "World",
62
+ :id => "attributes", :class => "test" ).to_s.should ==
63
+ '<testing id="attributes" class="test">Hello World</testing>'
64
+ end
65
+
66
+ it "Allows yielding for internal content" do
67
+ def page
68
+ html do
69
+ body do
70
+ yield
71
+ end
72
+ end
73
+ end
74
+
75
+ page do
76
+ P "Internal Content"
77
+ end.to_s.should == "<html><body><p>Internal Content</p></body></html>"
78
+ end
79
+
80
+ it "Does not auto-style" do
81
+ html do
82
+ head do
83
+ style do
84
+ body do
85
+ color :blue
86
+ end
87
+ end
88
+ end
89
+ end.to_s.should == "<html><head><style><body><color>blue</color></body></style></head></html>"
90
+ end
91
+
92
+ end
@@ -0,0 +1,55 @@
1
+ require 'rubygems'
2
+ require 'xml/libxml'
3
+
4
+ def process_element( element, level = 0)
5
+ children = 0
6
+ element.each_child { children+=1 }
7
+
8
+ if element.text?
9
+ text = element.to_s.strip
10
+ return if text.size == 0
11
+ else
12
+ if children == 1 and element.child.name == "text"
13
+ text = element.child.to_s.strip
14
+ else
15
+ text = nil
16
+ end
17
+ end
18
+
19
+ element.name = "P" if element.name == "p"
20
+
21
+ indentation = ' '*level
22
+ print indentation + "#{element.name.strip}"
23
+
24
+ if text and element.name != "text"
25
+ print " \"#{text}\""
26
+ end
27
+
28
+ attributes=[]
29
+ element.each_attr do |attribute|
30
+ if attribute.name.grep( /-/ ).size > 0
31
+ attributes << "\"#{attribute.name}\" => \"#{attribute.value}\""
32
+ else
33
+ attributes << ":#{attribute.name} => \"#{attribute.value}\""
34
+ end
35
+ end
36
+ if not attributes.empty?
37
+ print "," if text and element.name != "text"
38
+ print " "+attributes.join(', ').strip
39
+ end
40
+ if not (text and element.name != "text")
41
+ if element.children?
42
+ puts " do"
43
+ element.each do |inner_element|
44
+ process_element( inner_element, level + 2 )
45
+ end
46
+ print indentation + "end" if element.children?
47
+ else
48
+ print " \"#{text}\"" if text
49
+ end
50
+ end
51
+ print "\n"
52
+ end
53
+
54
+ html = XML::Document.file( ARGV[0] )
55
+ process_element( html.root )
metadata CHANGED
@@ -1,53 +1,134 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.4
3
- specification_version: 1
4
2
  name: Remarkably
5
3
  version: !ruby/object:Gem::Version
6
- version: 0.5.2
7
- date: 2007-05-26 00:00:00 +02:00
8
- summary: Remarkably is a very tiny Markaby-like XML builder
9
- require_paths:
10
- - lib
11
- email: clive@darkarts.co.za
12
- homepage: http://www.darkarts.co.za/
13
- rubyforge_project:
14
- description:
15
- autorequire:
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: false
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 6
8
+ - 0
9
+ version: 0.6.0
25
10
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
11
  authors:
30
12
  - Clive Crous
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-01-20 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: bundler
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 0
30
+ - 0
31
+ version: 1.0.0
32
+ type: :development
33
+ prerelease: false
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: rake
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ segments:
43
+ - 0
44
+ - 8
45
+ - 7
46
+ version: 0.8.7
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: rspec
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ segments:
58
+ - 1
59
+ - 3
60
+ - 0
61
+ version: 1.3.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: *id003
65
+ description: Remarkably is a very tiny Markaby-like XML,HTML and CSS builder
66
+ email:
67
+ - clive@crous.co.za
68
+ executables: []
69
+
70
+ extensions: []
71
+
72
+ extra_rdoc_files: []
73
+
31
74
  files:
32
- - lib/remarkably
75
+ - .gitignore
76
+ - Gemfile
77
+ - README
78
+ - Rakefile
79
+ - examples/basic_css.rb
80
+ - examples/basic_html.rb
81
+ - examples/basic_xml.rb
82
+ - examples/bookmarklets.rb
83
+ - examples/headerfooter.rb
84
+ - examples/pages.rb
33
85
  - lib/remarkably.rb
34
- - lib/remarkably/engines
35
- - lib/remarkably/engines/css
36
- - lib/remarkably/engines/xml.rb
37
- - lib/remarkably/engines/html.rb
38
86
  - lib/remarkably/engines/css.rb
39
87
  - lib/remarkably/engines/css/helpers.rb
40
- test_files: []
88
+ - lib/remarkably/engines/html.rb
89
+ - lib/remarkably/engines/html/helpers.rb
90
+ - lib/remarkably/engines/xml.rb
91
+ - lib/remarkably/version.rb
92
+ - loadpath.rb
93
+ - remarkably.gemspec
94
+ - spec/engines/css.rb
95
+ - spec/engines/css/helpers.rb
96
+ - spec/engines/html.rb
97
+ - spec/engines/xml.rb
98
+ - utility/html2rem.rb
99
+ has_rdoc: true
100
+ homepage: http://www.darkarts.co.za/remarkably
101
+ licenses: []
41
102
 
103
+ post_install_message:
42
104
  rdoc_options: []
43
105
 
44
- extra_rdoc_files: []
45
-
46
- executables: []
47
-
48
- extensions: []
49
-
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ hash: 880848145
114
+ segments:
115
+ - 0
116
+ version: "0"
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ hash: 880848145
123
+ segments:
124
+ - 0
125
+ version: "0"
50
126
  requirements: []
51
127
 
52
- dependencies: []
128
+ rubyforge_project:
129
+ rubygems_version: 1.3.7
130
+ signing_key:
131
+ specification_version: 3
132
+ summary: A very tiny Markaby-like XML,HTML and CSS builder
133
+ test_files: []
53
134