rhtml 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Rhtml
2
2
 
3
3
  A DSL to write html in pure ruby.
4
- **write test tomorror**
4
+ **write test tomorrow**
5
5
 
6
6
  ## Installation
7
7
 
@@ -20,20 +20,23 @@ Or install it yourself as:
20
20
  ## Usage
21
21
 
22
22
  ```ruby
23
- html! {
23
+ Rhtml.html! {
24
24
  body {
25
25
  div(class: "post", id: 1) {
26
26
  title "first post"
27
27
  br
28
28
  p "hello world"
29
29
  div(class: "comment") {
30
- p(class: "grey") {
31
- "No comments yet."
32
- }
30
+ (1..5).each do |id|
31
+ p(class: "grey") {
32
+ "comment #{id}"
33
+ }
34
+ end
33
35
  }
34
36
  }
35
37
  }
36
38
  }
39
+
37
40
  ```
38
41
  ** converted to html **
39
42
 
@@ -42,15 +45,27 @@ html! {
42
45
  <body>
43
46
  <div class='post' id='1'>
44
47
  <title>
45
- first post
48
+ first post
46
49
  </title>
47
- <br />
50
+ <br/>
48
51
  <p>
49
- hello world
52
+ hello world
50
53
  </p>
51
54
  <div class='comment'>
52
55
  <p class='grey'>
53
- No comments yet.
56
+ comment 1
57
+ </p>
58
+ <p class='grey'>
59
+ comment 2
60
+ </p>
61
+ <p class='grey'>
62
+ comment 3
63
+ </p>
64
+ <p class='grey'>
65
+ comment 4
66
+ </p>
67
+ <p class='grey'>
68
+ comment 5
54
69
  </p>
55
70
  </div>
56
71
  </div>
@@ -1,70 +1,4 @@
1
- class Html
2
- attr_accessor :content, :indent
3
-
4
- INDENT = ' '
5
- VOID_TAGS = %w{area base br col command embed hr img input keygen link meta param source track wbr}
6
-
7
- def initialize(content='', indent=0, &b)
8
- @indent = 0
9
- @content = content
10
- @content << instance_eval(&b) if block_given?
11
- end
12
-
13
- def method_missing(tag_name, ps={}, str=nil, &b)
14
-
15
- if ps.is_a? String
16
- str, ps = ps, {}
17
- end
18
-
19
- tag_name = tag_name.to_s
20
- if VOID_TAGS.include? tag_name
21
- content << void_tag(tag_name, ps)
22
- else
23
- content << tag_open(tag_name, ps)
24
- @indent += 1
25
- if str
26
- content << str << "\n"
27
- elsif block_given?
28
- ret = instance_eval &b
29
- content << ret.to_s << "\n" unless ret.is_a?(self.class)
30
- end
31
- @indent -= 1
32
- self.content << tag_close(tag_name)
33
- end
34
-
35
- self
36
- end
37
-
38
- # conflict with global p method
39
- def p(ps={}, &b)
40
- method_missing("p", ps, &b)
41
- end
42
-
43
- def properties ps
44
- ps.map { |p| "#{p[0].to_s.gsub("_", "-")}='#{p[1].to_s}'" }.join(' ')
45
- end
46
-
47
- def tag_open tag_name, ps={}
48
- if ps.empty?
49
- "#{INDENT * indent}<#{tag_name}>\n"
50
- else
51
- "#{INDENT * indent}<#{tag_name} #{properties ps}>\n"
52
- end
53
- end
54
-
55
- def tag_close tag_name
56
- "#{INDENT * indent}</#{tag_name}>\n"
57
- end
58
-
59
- def void_tag tag_name, ps={}
60
- "#{INDENT * indent}<#{tag_name} #{properties ps}/>\n"
61
- end
62
-
63
- def to_s
64
- content
65
- end
66
- end
67
-
68
- def html!(&b)
69
- Html.new.html(&b)
70
- end
1
+ require 'rhtml/version'
2
+ require 'rhtml/tag'
3
+ require 'rhtml/html'
4
+ require 'rhtml/shortcut'
@@ -0,0 +1,51 @@
1
+ module Rhtml
2
+ class Html
3
+ attr_accessor :content, :indent
4
+
5
+ def initialize(content='', indent=0, &b)
6
+ @indent = 0
7
+ @content = content
8
+ @content << instance_eval(&b) if block_given?
9
+ end
10
+
11
+ def tag!(tag_name, ps={}, str=nil, &b)
12
+ str, ps = ps, {} if ps.is_a? String
13
+ content << Rhtml.tag_open(tag_name, ps, indent)
14
+ @indent += 1
15
+ if str
16
+ content << INDENT * indent << str << "\n"
17
+ elsif block_given?
18
+ ret = instance_eval &b
19
+ content << INDENT * indent << ret.to_s << "\n" if ret.is_a?(String)
20
+ end
21
+ @indent -= 1
22
+ self.content << Rhtml.tag_close(tag_name, indent)
23
+ self
24
+ end
25
+
26
+ def void_tag!(tag_name, ps={})
27
+ content << Rhtml.void_tag(tag_name, ps, indent)
28
+ self
29
+ end
30
+
31
+ TAGS.each do |m|
32
+ if VOID_TAGS.include? m
33
+ define_method(m.to_sym) do |ps={}|
34
+ void_tag!(m, ps)
35
+ end
36
+ else
37
+ define_method(m.to_sym) do |ps={}, str=nil, &b|
38
+ tag!(m, ps, str, &b)
39
+ end
40
+ end
41
+ end
42
+
43
+ def raw! string=''
44
+ @content << string.to_s << "\n"
45
+ end
46
+
47
+ def to_s
48
+ content
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,5 @@
1
+ module Rhtml
2
+ def Rhtml.html!(&b)
3
+ Rhtml::Html.new.html(&b)
4
+ end
5
+ end
@@ -0,0 +1,31 @@
1
+ module Rhtml
2
+
3
+ INDENT = ' '
4
+
5
+ VOID_TAGS = %w{area base br col command embed hr img input keygen link meta param source track wbr}
6
+
7
+ TAGS = %w{a abbr acronym address applet area article aside audio b base basefont bdi
8
+ bdo big blockquote body br canvas caption center cite code col colgroup command
9
+ datalist dd del details dfn dialog dir div dl dt em embed fieldset figcaption
10
+ figure font footer form frame frameset h1 head header hgroup hr html i iframe
11
+ img input ins kbd keygen label legend li link map mark menu meta meter nav noframes
12
+ noscript object ol optgroup option output p param pre progress q rp rt ruby s samp
13
+ script section select small source span strike strong style sub summary sup table tbody
14
+ td textarea tfoot th thead time title tr track tt u ul var video wbr}
15
+
16
+ def Rhtml.properties ps
17
+ ps.map { |p| "#{p[0].to_s.gsub("_", "-")}='#{p[1].to_s}'" }.join(' ')
18
+ end
19
+
20
+ def Rhtml.void_tag tag_name, ps={}, indent
21
+ "#{INDENT * indent}<#{tag_name}#{' ' << properties(ps) unless ps.empty?}/>\n"
22
+ end
23
+
24
+ def Rhtml.tag_open tag_name, ps={}, indent
25
+ "#{INDENT * indent}<#{tag_name}#{' ' << properties(ps) unless ps.empty?}>\n"
26
+ end
27
+
28
+ def Rhtml.tag_close tag_name, indent
29
+ "#{INDENT * indent}</#{tag_name}>\n"
30
+ end
31
+ end
@@ -1,3 +1,3 @@
1
1
  module Rhtml
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,18 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rhtml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - wenjun.yan
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-07-25 00:00:00.000000000 Z
12
+ date: 2013-07-29 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: bundler
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
19
  - - ~>
18
20
  - !ruby/object:Gem::Version
@@ -20,6 +22,7 @@ dependencies:
20
22
  type: :development
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
27
  - - ~>
25
28
  - !ruby/object:Gem::Version
@@ -27,6 +30,7 @@ dependencies:
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: rake
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
35
  - - ! '>='
32
36
  - !ruby/object:Gem::Version
@@ -34,6 +38,7 @@ dependencies:
34
38
  type: :development
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
43
  - - ! '>='
39
44
  - !ruby/object:Gem::Version
@@ -51,30 +56,35 @@ files:
51
56
  - README.md
52
57
  - Rakefile
53
58
  - lib/rhtml.rb
59
+ - lib/rhtml/html.rb
60
+ - lib/rhtml/shortcut.rb
61
+ - lib/rhtml/tag.rb
54
62
  - lib/rhtml/version.rb
55
63
  - rhtml.gemspec
56
64
  homepage: https://github.com/v2e4lisp/rhtml
57
65
  licenses:
58
66
  - MIT
59
- metadata: {}
60
67
  post_install_message:
61
68
  rdoc_options: []
62
69
  require_paths:
63
70
  - lib
64
71
  required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
65
73
  requirements:
66
74
  - - ! '>='
67
75
  - !ruby/object:Gem::Version
68
76
  version: '0'
69
77
  required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
70
79
  requirements:
71
80
  - - ! '>='
72
81
  - !ruby/object:Gem::Version
73
82
  version: '0'
74
83
  requirements: []
75
84
  rubyforge_project:
76
- rubygems_version: 2.0.5
85
+ rubygems_version: 1.8.25
77
86
  signing_key:
78
- specification_version: 4
87
+ specification_version: 3
79
88
  summary: writing html in ruby not inserting them in a template...
80
89
  test_files: []
90
+ has_rdoc:
checksums.yaml DELETED
@@ -1,15 +0,0 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- NGVhMzMzZDg1M2ZiYTQyMjE5NWY5OWVkZWU5YTE0NDcxMTkyY2I3Zg==
5
- data.tar.gz: !binary |-
6
- NmYzMmI1ZGJiMWI3YzVhZWU0ZWEwZWRiMTVhNGNmMTBhYjc0ZjRiMw==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- MDQ4MmM4NmFlZDY0MGQzNjEyZjQ1ZTNjMDViMGI1NTI4NzdhOWIyNjUxNWE4
10
- MTYzMGMzYzFiZThmZjM4MjE5M2E1Y2NlZDIxNzQxMWZkMGY1MmI5ZmQxMjE3
11
- M2U0YzFkNGYzYWMzZGYwMThiY2VmYjg4Y2NiNzgzNTFjZWVmZGI=
12
- data.tar.gz: !binary |-
13
- NjdjYWYyNDVmNDQ3ZjhmNmJmNTBlNWI3NWU4MWJkNTkzNjM3Zjk2NjZmMTk3
14
- YmY4ZWE4NGM5MjdiMjgzZjA5ZDhhZTNmM2Q2NzAwZjEyMDlhYzc5Zjk5ZWFm
15
- MjJhZDlmZDUwMDUyYWQwOTRhNDVmMzc3YjhmMGViNmJjYjdiMzk=