htmr 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/Rakefile +1 -0
- data/htmr.gemspec +19 -0
- data/lib/htmr.rb +6 -0
- data/lib/htmr/application.rb +96 -0
- data/lib/htmr/version.rb +6 -0
- data/script/console +7 -0
- data/script/test +25 -0
- metadata +65 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/htmr.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "htmr/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "htmr"
|
7
|
+
s.version = HTMr::VERSION
|
8
|
+
s.authors = ["James Birtles"]
|
9
|
+
s.email = ["itsme@jamesbirtles.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{HTMr is a way of writing html in ruby}
|
12
|
+
s.description = %q{HTMr is a way of writing html (and a bit of javascript) in ruby}
|
13
|
+
s.files = `git ls-files`.split("\n")
|
14
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
15
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
|
18
|
+
s.add_development_dependency "pry"
|
19
|
+
end
|
data/lib/htmr.rb
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
module HTMr
|
2
|
+
class Application
|
3
|
+
def method_missing(name, *args, &block)
|
4
|
+
if @type == :js
|
5
|
+
@cur_elem = name
|
6
|
+
else
|
7
|
+
if name == :on
|
8
|
+
# TODO: do something with javascript
|
9
|
+
else
|
10
|
+
name = :p if name == :para
|
11
|
+
@elem_depth[name] = {:properties => {}}
|
12
|
+
unless args[0].class == Hash
|
13
|
+
@elem_depth[name][:properties].merge!({ :text => args[0] })
|
14
|
+
args.delete_at 0
|
15
|
+
end
|
16
|
+
@elem_depth[name][:properties].merge!(args[0]) unless args.empty?
|
17
|
+
old_elem_depth = @elem_depth
|
18
|
+
prev_elem = @cur_elem
|
19
|
+
@elem_depth = @elem_depth[name]
|
20
|
+
@cur_elem = name
|
21
|
+
instance_eval &block if block
|
22
|
+
@cur_elem = prev_elem
|
23
|
+
@elem_depth = old_elem_depth
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def p *args, &block
|
29
|
+
para *args, &block
|
30
|
+
end
|
31
|
+
|
32
|
+
def initialize(title, &block)
|
33
|
+
puts "Creating new app called '#{title}'"
|
34
|
+
@elements = {
|
35
|
+
:html => {
|
36
|
+
:head => {
|
37
|
+
:title => {
|
38
|
+
:properties => {
|
39
|
+
:text => title
|
40
|
+
}
|
41
|
+
}
|
42
|
+
},
|
43
|
+
:body => {}
|
44
|
+
}
|
45
|
+
}
|
46
|
+
@elem_depth = @elements[:html][:body]
|
47
|
+
@cur_elem = :body
|
48
|
+
@type = :html
|
49
|
+
@indent = 0
|
50
|
+
instance_eval &block if block
|
51
|
+
end
|
52
|
+
|
53
|
+
def render
|
54
|
+
render_each @elements
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
def generate_js_from_block &block
|
59
|
+
@type = :js
|
60
|
+
instance_eval &block
|
61
|
+
@type = :html
|
62
|
+
end
|
63
|
+
|
64
|
+
def render_each elements
|
65
|
+
render = ""
|
66
|
+
elements.each do |element, hash|
|
67
|
+
if element == :properties
|
68
|
+
render = element
|
69
|
+
break
|
70
|
+
else
|
71
|
+
@indent += 1
|
72
|
+
props = ""
|
73
|
+
text = ""
|
74
|
+
content = render_each(hash)
|
75
|
+
if content == :properties
|
76
|
+
properties = hash[:properties]
|
77
|
+
properties.each do |property, value|
|
78
|
+
if property == :text
|
79
|
+
text << value
|
80
|
+
else
|
81
|
+
props << " #{property.to_s}=\"#{value}\""
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
hash.delete(:properties)
|
86
|
+
content = render_each(hash)
|
87
|
+
end
|
88
|
+
text = "#{" " * @indent}#{text}\n" unless text == ""
|
89
|
+
render << "#{" " * (@indent - 1)}<#{element.to_s}#{props}>\n#{text}#{content}#{" " * (@indent -1 )}</#{element.to_s}>\n"
|
90
|
+
@indent -= 1
|
91
|
+
end
|
92
|
+
end
|
93
|
+
render
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
data/lib/htmr/version.rb
ADDED
data/script/console
ADDED
data/script/test
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$:.push File.expand_path("../../lib", __FILE__)
|
3
|
+
require "htmr"
|
4
|
+
|
5
|
+
app = HTMr::Application.new "My App" do
|
6
|
+
header :width => "500", :style => "color: white;" do
|
7
|
+
h1 "Hello World", :style => "color: black;" do
|
8
|
+
on :click, %Q{
|
9
|
+
clicked = document.getElementById("clicked");
|
10
|
+
clicked.innerHTML = "You clicked a #{@cur_elem} tag!"
|
11
|
+
}
|
12
|
+
end
|
13
|
+
end
|
14
|
+
section "hi" do
|
15
|
+
p "hello", :style => "color: black;" do
|
16
|
+
p "world" do
|
17
|
+
on :click, %Q{
|
18
|
+
clicked = document.getElementById("clicked");
|
19
|
+
clicked.innerHTML = "You clicked a #{@cur_elem} tag!"
|
20
|
+
}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
puts app.render
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: htmr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- James Birtles
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-10-25 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: pry
|
16
|
+
requirement: &70335081175740 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70335081175740
|
25
|
+
description: HTMr is a way of writing html (and a bit of javascript) in ruby
|
26
|
+
email:
|
27
|
+
- itsme@jamesbirtles.com
|
28
|
+
executables: []
|
29
|
+
extensions: []
|
30
|
+
extra_rdoc_files: []
|
31
|
+
files:
|
32
|
+
- .gitignore
|
33
|
+
- Gemfile
|
34
|
+
- Rakefile
|
35
|
+
- htmr.gemspec
|
36
|
+
- lib/htmr.rb
|
37
|
+
- lib/htmr/application.rb
|
38
|
+
- lib/htmr/version.rb
|
39
|
+
- script/console
|
40
|
+
- script/test
|
41
|
+
homepage: ''
|
42
|
+
licenses: []
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
none: false
|
49
|
+
requirements:
|
50
|
+
- - ! '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ! '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
requirements: []
|
60
|
+
rubyforge_project:
|
61
|
+
rubygems_version: 1.8.10
|
62
|
+
signing_key:
|
63
|
+
specification_version: 3
|
64
|
+
summary: HTMr is a way of writing html in ruby
|
65
|
+
test_files: []
|