rhtml 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
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=
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rhtml.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 wenjun.yan
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # Rhtml
2
+
3
+ A DSL to write html in pure ruby.
4
+ **write test tomorror**
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'rhtml'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install rhtml
19
+
20
+ ## Usage
21
+
22
+ ```ruby
23
+ html! {
24
+ body {
25
+ div(class: "post", id: 1) {
26
+ title "first post"
27
+ br
28
+ p "hello world"
29
+ div(class: "comment") {
30
+ p(class: "grey") {
31
+ "No comments yet."
32
+ }
33
+ }
34
+ }
35
+ }
36
+ }
37
+ ```
38
+ ** converted to html **
39
+
40
+ ```html
41
+ <html>
42
+ <body>
43
+ <div class='post' id='1'>
44
+ <title>
45
+ first post
46
+ </title>
47
+ <br />
48
+ <p>
49
+ hello world
50
+ </p>
51
+ <div class='comment'>
52
+ <p class='grey'>
53
+ No comments yet.
54
+ </p>
55
+ </div>
56
+ </div>
57
+ </body>
58
+ </html>
59
+ ```
60
+
61
+ ## Contributing
62
+
63
+ 1. Fork it
64
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
65
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
66
+ 4. Push to the branch (`git push origin my-new-feature`)
67
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/lib/rhtml.rb ADDED
@@ -0,0 +1,70 @@
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
@@ -0,0 +1,3 @@
1
+ module Rhtml
2
+ VERSION = "0.0.2"
3
+ end
data/rhtml.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rhtml/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rhtml"
8
+ spec.version = Rhtml::VERSION
9
+ spec.authors = ["wenjun.yan"]
10
+ spec.email = ["mylastnameisyan@gmail.com"]
11
+ spec.description = %q{a little dsl that let you write html in ruby , pure ruby.}
12
+ spec.summary = %q{writing html in ruby not inserting them in a template...}
13
+ spec.homepage = "https://github.com/v2e4lisp/rhtml"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rhtml
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - wenjun.yan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: a little dsl that let you write html in ruby , pure ruby.
42
+ email:
43
+ - mylastnameisyan@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - lib/rhtml.rb
54
+ - lib/rhtml/version.rb
55
+ - rhtml.gemspec
56
+ homepage: https://github.com/v2e4lisp/rhtml
57
+ licenses:
58
+ - MIT
59
+ metadata: {}
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 2.0.5
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: writing html in ruby not inserting them in a template...
80
+ test_files: []