green_monkey 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +2 -2
- data/Gemfile +2 -2
- data/Gemfile.haml-edge +3 -2
- data/Gemfile.lock +54 -55
- data/Gemfile.rails-3.0 +5 -0
- data/Gemfile.rails-3.1 +5 -0
- data/Gemfile.rails-3.2 +2 -2
- data/README.md +3 -4
- data/green_monkey.gemspec +3 -3
- data/lib/green_monkey/ext/action_view.rb +13 -13
- data/lib/green_monkey/ext/active_model.rb +2 -1
- data/lib/green_monkey/ext/haml.rb +8 -9
- data/lib/green_monkey/ext/mida.rb +0 -8
- data/lib/green_monkey/ext/view_helper.rb +37 -11
- data/lib/green_monkey/railtie.rb +4 -3
- data/lib/green_monkey.rb +31 -1
- data/sinatra_app/Gemfile +5 -0
- data/sinatra_app/Gemfile.lock +71 -0
- data/sinatra_app/app.rb +38 -0
- data/sinatra_app/app_haml.rb +33 -0
- data/sinatra_app/config.ru +0 -0
- data/spec/action_view_spec.rb +27 -3
- data/spec/haml_spec.rb +14 -0
- data/spec/post.haml +1 -1
- metadata +72 -27
- data/Gemfile.rails-3.0.11 +0 -5
- data/Gemfile.rails-3.1.3 +0 -5
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
source :rubygems
|
2
2
|
gemspec
|
3
|
-
gem "mida", git: 'git
|
4
|
-
gem "rails", "3.2.
|
3
|
+
gem "mida", git: 'git://github.com/Paxa/mida.git', ref: '5289a3be1'
|
4
|
+
gem "rails", "3.2.3"
|
5
5
|
gem 'chronic_duration', git: 'git://github.com/Paxa/chronic_duration.git', ref: '8c0d0e101b'
|
data/Gemfile.haml-edge
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
source :rubygems
|
2
2
|
gemspec
|
3
3
|
gem "haml", git: "https://github.com/nex3/haml.git", ref: "630b8fe2033e6"
|
4
|
-
gem "mida", git: 'git
|
5
|
-
gem 'chronic_duration', git: 'git://github.com/Paxa/chronic_duration.git', ref: '8c0d0e101b'
|
4
|
+
gem "mida", git: 'git://github.com/Paxa/mida.git', ref: '7db7149a2cf'
|
5
|
+
gem 'chronic_duration', git: 'git://github.com/Paxa/chronic_duration.git', ref: '8c0d0e101b'
|
6
|
+
gem 'tzinfo'
|
data/Gemfile.lock
CHANGED
@@ -7,9 +7,9 @@ GIT
|
|
7
7
|
numerizer (~> 0.1.1)
|
8
8
|
|
9
9
|
GIT
|
10
|
-
remote: git
|
11
|
-
revision:
|
12
|
-
ref:
|
10
|
+
remote: git://github.com/Paxa/mida.git
|
11
|
+
revision: 5289a3be11941f4698136fafddd1c2218765181a
|
12
|
+
ref: 5289a3be1
|
13
13
|
specs:
|
14
14
|
mida (0.3.4)
|
15
15
|
mida_vocabulary (>= 0.1)
|
@@ -18,43 +18,42 @@ GIT
|
|
18
18
|
PATH
|
19
19
|
remote: .
|
20
20
|
specs:
|
21
|
-
green_monkey (0.1.
|
21
|
+
green_monkey (0.1.2)
|
22
22
|
chronic_duration
|
23
23
|
haml (>= 3.1.0)
|
24
24
|
mida_vocabulary (>= 0.1)
|
25
|
-
rails (>= 3.0.0)
|
26
25
|
|
27
26
|
GEM
|
28
27
|
remote: http://rubygems.org/
|
29
28
|
specs:
|
30
|
-
actionmailer (3.2.
|
31
|
-
actionpack (= 3.2.
|
32
|
-
mail (~> 2.
|
33
|
-
actionpack (3.2.
|
34
|
-
activemodel (= 3.2.
|
35
|
-
activesupport (= 3.2.
|
29
|
+
actionmailer (3.2.3)
|
30
|
+
actionpack (= 3.2.3)
|
31
|
+
mail (~> 2.4.4)
|
32
|
+
actionpack (3.2.3)
|
33
|
+
activemodel (= 3.2.3)
|
34
|
+
activesupport (= 3.2.3)
|
36
35
|
builder (~> 3.0.0)
|
37
36
|
erubis (~> 2.7.0)
|
38
|
-
journey (~> 1.0.
|
37
|
+
journey (~> 1.0.1)
|
39
38
|
rack (~> 1.4.0)
|
40
|
-
rack-cache (~> 1.
|
39
|
+
rack-cache (~> 1.2)
|
41
40
|
rack-test (~> 0.6.1)
|
42
41
|
sprockets (~> 2.1.2)
|
43
|
-
activemodel (3.2.
|
44
|
-
activesupport (= 3.2.
|
42
|
+
activemodel (3.2.3)
|
43
|
+
activesupport (= 3.2.3)
|
45
44
|
builder (~> 3.0.0)
|
46
|
-
activerecord (3.2.
|
47
|
-
activemodel (= 3.2.
|
48
|
-
activesupport (= 3.2.
|
49
|
-
arel (~> 3.0.
|
45
|
+
activerecord (3.2.3)
|
46
|
+
activemodel (= 3.2.3)
|
47
|
+
activesupport (= 3.2.3)
|
48
|
+
arel (~> 3.0.2)
|
50
49
|
tzinfo (~> 0.3.29)
|
51
|
-
activeresource (3.2.
|
52
|
-
activemodel (= 3.2.
|
53
|
-
activesupport (= 3.2.
|
54
|
-
activesupport (3.2.
|
50
|
+
activeresource (3.2.3)
|
51
|
+
activemodel (= 3.2.3)
|
52
|
+
activesupport (= 3.2.3)
|
53
|
+
activesupport (3.2.3)
|
55
54
|
i18n (~> 0.6)
|
56
55
|
multi_json (~> 1.0)
|
57
|
-
arel (3.0.
|
56
|
+
arel (3.0.2)
|
58
57
|
blankslate (2.1.2.4)
|
59
58
|
builder (3.0.0)
|
60
59
|
diff-lcs (1.1.3)
|
@@ -62,37 +61,37 @@ GEM
|
|
62
61
|
haml (3.1.4)
|
63
62
|
hike (1.2.1)
|
64
63
|
i18n (0.6.0)
|
65
|
-
journey (1.0.
|
66
|
-
json (1.6.
|
67
|
-
mail (2.
|
64
|
+
journey (1.0.3)
|
65
|
+
json (1.6.6)
|
66
|
+
mail (2.4.4)
|
68
67
|
i18n (>= 0.4.0)
|
69
68
|
mime-types (~> 1.16)
|
70
69
|
treetop (~> 1.4.8)
|
71
|
-
mida_vocabulary (0.1)
|
70
|
+
mida_vocabulary (0.1.3)
|
72
71
|
blankslate
|
73
|
-
mime-types (1.
|
74
|
-
multi_json (1.0
|
75
|
-
nokogiri (1.5.
|
72
|
+
mime-types (1.18)
|
73
|
+
multi_json (1.2.0)
|
74
|
+
nokogiri (1.5.2)
|
76
75
|
numerizer (0.1.1)
|
77
76
|
polyglot (0.3.3)
|
78
|
-
rack (1.4.
|
79
|
-
rack-cache (1.
|
77
|
+
rack (1.4.1)
|
78
|
+
rack-cache (1.2)
|
80
79
|
rack (>= 0.4)
|
81
80
|
rack-ssl (1.3.2)
|
82
81
|
rack
|
83
82
|
rack-test (0.6.1)
|
84
83
|
rack (>= 1.0)
|
85
|
-
rails (3.2.
|
86
|
-
actionmailer (= 3.2.
|
87
|
-
actionpack (= 3.2.
|
88
|
-
activerecord (= 3.2.
|
89
|
-
activeresource (= 3.2.
|
90
|
-
activesupport (= 3.2.
|
84
|
+
rails (3.2.3)
|
85
|
+
actionmailer (= 3.2.3)
|
86
|
+
actionpack (= 3.2.3)
|
87
|
+
activerecord (= 3.2.3)
|
88
|
+
activeresource (= 3.2.3)
|
89
|
+
activesupport (= 3.2.3)
|
91
90
|
bundler (~> 1.0)
|
92
|
-
railties (= 3.2.
|
93
|
-
railties (3.2.
|
94
|
-
actionpack (= 3.2.
|
95
|
-
activesupport (= 3.2.
|
91
|
+
railties (= 3.2.3)
|
92
|
+
railties (3.2.3)
|
93
|
+
actionpack (= 3.2.3)
|
94
|
+
activesupport (= 3.2.3)
|
96
95
|
rack-ssl (~> 1.3.2)
|
97
96
|
rake (>= 0.8.7)
|
98
97
|
rdoc (~> 3.4)
|
@@ -100,19 +99,19 @@ GEM
|
|
100
99
|
rake (0.9.2.2)
|
101
100
|
rdoc (3.12)
|
102
101
|
json (~> 1.4)
|
103
|
-
rspec (2.
|
104
|
-
rspec-core (~> 2.
|
105
|
-
rspec-expectations (~> 2.
|
106
|
-
rspec-mocks (~> 2.
|
107
|
-
rspec-core (2.
|
108
|
-
rspec-expectations (2.
|
109
|
-
diff-lcs (~> 1.1.
|
110
|
-
rspec-mocks (2.
|
111
|
-
rspec-rails (2.
|
102
|
+
rspec (2.9.0)
|
103
|
+
rspec-core (~> 2.9.0)
|
104
|
+
rspec-expectations (~> 2.9.0)
|
105
|
+
rspec-mocks (~> 2.9.0)
|
106
|
+
rspec-core (2.9.0)
|
107
|
+
rspec-expectations (2.9.1)
|
108
|
+
diff-lcs (~> 1.1.3)
|
109
|
+
rspec-mocks (2.9.0)
|
110
|
+
rspec-rails (2.9.0)
|
112
111
|
actionpack (>= 3.0)
|
113
112
|
activesupport (>= 3.0)
|
114
113
|
railties (>= 3.0)
|
115
|
-
rspec (~> 2.
|
114
|
+
rspec (~> 2.9.0)
|
116
115
|
sprockets (2.1.2)
|
117
116
|
hike (~> 1.2)
|
118
117
|
rack (~> 1.0)
|
@@ -123,7 +122,7 @@ GEM
|
|
123
122
|
treetop (1.4.10)
|
124
123
|
polyglot
|
125
124
|
polyglot (>= 0.3.1)
|
126
|
-
tzinfo (0.3.
|
125
|
+
tzinfo (0.3.33)
|
127
126
|
|
128
127
|
PLATFORMS
|
129
128
|
ruby
|
@@ -133,7 +132,7 @@ DEPENDENCIES
|
|
133
132
|
chronic_duration!
|
134
133
|
green_monkey!
|
135
134
|
mida!
|
136
|
-
rails (= 3.2.
|
135
|
+
rails (= 3.2.3)
|
137
136
|
rspec (>= 2.7.0)
|
138
137
|
rspec-rails
|
139
138
|
sqlite3
|
data/Gemfile.rails-3.0
ADDED
data/Gemfile.rails-3.1
ADDED
data/Gemfile.rails-3.2
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
source :rubygems
|
2
2
|
gemspec
|
3
|
-
gem "rails", "3.2.
|
4
|
-
gem "mida", git: 'git
|
3
|
+
gem "rails", "3.2.2"
|
4
|
+
gem "mida", git: 'git://github.com/Paxa/mida.git', ref: '7db7149a2cf'
|
5
5
|
gem 'chronic_duration', git: 'git://github.com/Paxa/chronic_duration.git', ref: '8c0d0e101b'
|
data/README.md
CHANGED
@@ -12,7 +12,6 @@ Add to Gemfile
|
|
12
12
|
|
13
13
|
```ruby
|
14
14
|
gem "green_monkey", '0.1.2'
|
15
|
-
gem "mida", git: 'git@github.com:Paxa/mida.git', ref: '7db7149a2cf'
|
16
15
|
gem 'chronic_duration', git: 'git://github.com/Paxa/chronic_duration.git', ref: '8c0d0e101b'
|
17
16
|
```
|
18
17
|
|
@@ -20,8 +19,8 @@ gem 'chronic_duration', git: 'git://github.com/Paxa/chronic_duration.git', ref:
|
|
20
19
|
|
21
20
|
### helper `time_tag`
|
22
21
|
|
23
|
-
It almost
|
24
|
-
Also it accepts Numeric values as duration
|
22
|
+
It almost the same with rails' time_tag but make `datetime` attribute in iso8601 format, according to Microdata specifications.
|
23
|
+
Also it accepts Numeric values as duration for time intervals
|
25
24
|
|
26
25
|
Haml & HTML:
|
27
26
|
|
@@ -59,7 +58,7 @@ class User < ActiveRecord::Base
|
|
59
58
|
end
|
60
59
|
|
61
60
|
User.html_schema_type #=> Mida::SchemaOrg::Person
|
62
|
-
User.find(1).html_schema_type
|
61
|
+
User.find(1).html_schema_type #=> Mida::SchemaOrg::Person
|
63
62
|
```
|
64
63
|
|
65
64
|
### Haml magic
|
data/green_monkey.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "green_monkey"
|
5
|
-
s.version = '0.1.
|
5
|
+
s.version = '0.1.4'
|
6
6
|
s.platform = Gem::Platform::RUBY
|
7
7
|
s.authors = ["Pavel Evstigneev"]
|
8
8
|
s.email = ["pavel.evst@gmail.com"]
|
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
|
|
12
12
|
|
13
13
|
s.required_rubygems_version = ">= 1.2.0"
|
14
14
|
|
15
|
-
s.add_runtime_dependency 'rails', '>= 3.0.0'
|
15
|
+
#s.add_runtime_dependency 'rails', '>= 3.0.0'
|
16
16
|
s.add_runtime_dependency 'haml', '>= 3.1.0'
|
17
17
|
s.add_runtime_dependency 'mida_vocabulary', '>= 0.1'
|
18
18
|
s.add_runtime_dependency 'chronic_duration'
|
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.add_development_dependency "bundler", ">= 1.0.0"
|
21
21
|
s.add_development_dependency "rspec", ">= 2.7.0"
|
22
22
|
s.add_development_dependency "rspec-rails"
|
23
|
-
|
23
|
+
s.add_development_dependency "mida"
|
24
24
|
s.add_development_dependency 'sqlite3'
|
25
25
|
|
26
26
|
s.files = `git ls-files`.split("\n")
|
@@ -1,22 +1,22 @@
|
|
1
1
|
module ActionView::Helpers::TagHelper
|
2
|
+
# Rails by default does not behave with itemscope as boolean attribute
|
3
|
+
# and renders it as itemscope="true"
|
4
|
+
|
5
|
+
# this changes make it render as itemscope="itemscope"
|
2
6
|
BOOLEAN_ATTRIBUTES.merge(['itemscope', :itemscope])
|
3
7
|
|
4
8
|
private
|
9
|
+
|
10
|
+
# this hack replaces itemscope="itemscope" => itemscope
|
11
|
+
# to make it follow standarts (http://www.w3.org/TR/microdata/#typed-items)
|
12
|
+
alias_method :tag_options_before_green_monkey, :tag_options
|
5
13
|
def tag_options(options, escape = true)
|
6
|
-
|
7
|
-
unless options.blank?
|
8
|
-
attrs = []
|
9
|
-
options.each_pair do |key, value|
|
10
|
-
if BOOLEAN_ATTRIBUTES.include?(key)
|
11
|
-
attrs << key.to_s if value
|
12
|
-
elsif !value.nil?
|
13
|
-
final_value = value.is_a?(Array) ? value.join(" ") : value
|
14
|
-
final_value = ERB::Util.html_escape(final_value) if escape
|
15
|
-
attrs << %(#{key}="#{final_value}")
|
16
|
-
end
|
17
|
-
end
|
14
|
+
str = tag_options_before_green_monkey(options, escape)
|
18
15
|
|
19
|
-
|
16
|
+
if options['itemscope'] || options[:itemscope]
|
17
|
+
str = (str + '').sub(/itemscope=('|")itemscope('|")/, 'itemscope').html_safe
|
20
18
|
end
|
19
|
+
|
20
|
+
str
|
21
21
|
end
|
22
22
|
end
|
@@ -9,7 +9,7 @@ module GreenMonkey
|
|
9
9
|
end
|
10
10
|
|
11
11
|
module ClassMethods
|
12
|
-
def html_schema_type(value = nil)
|
12
|
+
def html_schema_type(value = nil, options = {})
|
13
13
|
return @html_schema_type unless value
|
14
14
|
|
15
15
|
value = /#{value}/ if value.is_a?(Symbol)
|
@@ -20,6 +20,7 @@ module GreenMonkey
|
|
20
20
|
end
|
21
21
|
|
22
22
|
@html_schema_type = value
|
23
|
+
@html_schema_options = options
|
23
24
|
end
|
24
25
|
end
|
25
26
|
end
|
@@ -27,7 +27,6 @@ class Haml::Buffer
|
|
27
27
|
next if obj == "local-variable"
|
28
28
|
self.class.merge_attrs(options, process_object_ref(obj))
|
29
29
|
end
|
30
|
-
|
31
30
|
options
|
32
31
|
end
|
33
32
|
|
@@ -39,24 +38,24 @@ class Haml::Buffer
|
|
39
38
|
return {'itemprop' => obj.to_s}
|
40
39
|
elsif obj.kind_of?(Mida::Vocabulary)
|
41
40
|
# Mida::Vocabulary => itemprop and itemtype
|
42
|
-
return {itemscope
|
41
|
+
return {'itemscope' => true, 'itemtype' => obj.itemtype.source}
|
43
42
|
elsif obj.is_a?(String)
|
44
|
-
return {class
|
43
|
+
return {'class' => obj}
|
45
44
|
else
|
46
45
|
options = {}
|
47
|
-
options[
|
48
|
-
options[
|
46
|
+
options['class'] = obj.respond_to?(:haml_object_ref) ? obj.haml_object_ref : underscore(obj.class)
|
47
|
+
options['id'] = "#{options['class']}_#{obj.id || 'new'}" if obj.respond_to?(:id)
|
49
48
|
|
50
49
|
# my hack for microdata attributes
|
51
50
|
if obj.respond_to?(:html_schema_type)
|
52
|
-
options[
|
53
|
-
options[
|
51
|
+
options['itemscope'] = true
|
52
|
+
options['itemid'] = obj.id
|
54
53
|
|
55
54
|
if obj.html_schema_type.kind_of?(Mida::Vocabulary)
|
56
|
-
options[
|
55
|
+
options['itemtype'] = obj.html_schema_type.itemtype.source
|
57
56
|
else
|
58
57
|
raise "No vocabulary found (#{obj.html_schema_type})" unless Mida::Vocabulary.find(obj.html_schema_type)
|
59
|
-
options[
|
58
|
+
options['itemtype'] = obj.html_schema_type
|
60
59
|
end
|
61
60
|
end
|
62
61
|
|
@@ -3,10 +3,10 @@
|
|
3
3
|
require "chronic_duration"
|
4
4
|
module GreenMonkey
|
5
5
|
module ViewHelper
|
6
|
-
|
6
|
+
|
7
7
|
# it shortcut for this
|
8
|
-
|
9
|
-
|
8
|
+
# %time{:datetime => post.published_at.iso8601(10) }= post.published_at.strftime("%d %h %Y")
|
9
|
+
|
10
10
|
# = time_tag post.created_at
|
11
11
|
# = time_tag post.created_at, format: "%d %h %Y %R%p"
|
12
12
|
# = time_tag post.created_at, itemprop: "datePublished"
|
@@ -14,23 +14,25 @@ module GreenMonkey
|
|
14
14
|
options = args.extract_options!
|
15
15
|
format = options.delete(:format) || :long
|
16
16
|
datetime = time_to_iso8601(time)
|
17
|
-
|
18
|
-
|
17
|
+
|
18
|
+
|
19
19
|
if time.acts_like?(:time)
|
20
20
|
title = nil
|
21
21
|
content = args.first || I18n.l(time, format: format)
|
22
22
|
elsif time.kind_of?(Numeric)
|
23
23
|
title = ChronicDuration.output(time, :format => format)
|
24
24
|
content = args.first || distance_of_time_in_words(time)
|
25
|
+
else
|
26
|
+
content = time.to_s
|
25
27
|
end
|
26
|
-
|
27
28
|
content_tag(:time, content, options.reverse_merge(datetime: datetime, title: title))
|
28
29
|
end
|
29
|
-
|
30
|
+
|
31
|
+
# as second argumnts can get as Time/DateTime object as duration in seconds
|
30
32
|
def time_tag_interval(from, to, *args)
|
31
33
|
options = args.extract_options!
|
32
34
|
format = options.delete(:format) || :long
|
33
|
-
|
35
|
+
|
34
36
|
datetime = [from, to].map(&method(:time_to_iso8601)).join("/")
|
35
37
|
content = args.first || [from, to].map do |time|
|
36
38
|
if time.acts_like?(:time)
|
@@ -39,16 +41,16 @@ module GreenMonkey
|
|
39
41
|
ChronicDuration.output(time, :format => format)
|
40
42
|
end
|
41
43
|
end
|
42
|
-
|
44
|
+
|
43
45
|
if to.acts_like?(:time)
|
44
46
|
content = content.join(" - ")
|
45
47
|
else
|
46
48
|
content = content.join(" in ")
|
47
49
|
end
|
48
|
-
|
50
|
+
|
49
51
|
content_tag(:time, content, options.reverse_merge(datetime: datetime))
|
50
52
|
end
|
51
|
-
|
53
|
+
|
52
54
|
def time_to_iso8601(time)
|
53
55
|
if time.acts_like?(:time)
|
54
56
|
time.iso8601
|
@@ -56,5 +58,29 @@ module GreenMonkey
|
|
56
58
|
ChronicDuration.output(time, :format => :iso8601)
|
57
59
|
end
|
58
60
|
end
|
61
|
+
|
62
|
+
def mida_scope(object)
|
63
|
+
options = {itemscope: true}
|
64
|
+
if object.respond_to?(:html_schema_type)
|
65
|
+
if object.html_schema_type.kind_of?(Mida::Vocabulary)
|
66
|
+
options.merge! itemtype: object.html_schema_type.itemtype.source
|
67
|
+
else
|
68
|
+
raise "No vocabulary found (#{obj.html_schema_type})" unless Mida::Vocabulary.find(obj.html_schema_type)
|
69
|
+
options.merge! itemtype: object.html_schema_type
|
70
|
+
end
|
71
|
+
elsif object.is_a?(Symbol)
|
72
|
+
options.merge! itemtype: Mida(object)
|
73
|
+
elsif object.is_a?(String)
|
74
|
+
options.merge! itemtype: object
|
75
|
+
end
|
76
|
+
|
77
|
+
tag_options(options)
|
78
|
+
end
|
79
|
+
|
80
|
+
def breadcrumb_link_to(title, path, options = {})
|
81
|
+
content_tag(:span, itemscope: true, itemtype: 'http://data-vocabulary.org/Breadcrumb') do
|
82
|
+
link_to(content_tag(:span, title, itemprop: 'title'), path, options.merge(itemprop: 'url')) + ''
|
83
|
+
end
|
84
|
+
end
|
59
85
|
end
|
60
86
|
end
|
data/lib/green_monkey/railtie.rb
CHANGED
@@ -2,13 +2,14 @@
|
|
2
2
|
|
3
3
|
module GreenMonkey
|
4
4
|
class Railtie < Rails::Railtie
|
5
|
-
initializer
|
5
|
+
initializer 'green_monkey.init', :before => :load_config_initializers do
|
6
6
|
require "green_monkey/ext/active_model"
|
7
7
|
ActiveModel::Dirty.send :include, GreenMonkey::ModelHelpers
|
8
|
-
|
8
|
+
ActiveRecord::Base.send :include, GreenMonkey::ModelHelpers
|
9
|
+
|
9
10
|
require 'green_monkey/ext/view_helper'
|
10
11
|
ActionView::Base.send :include, GreenMonkey::ViewHelper
|
11
|
-
|
12
|
+
|
12
13
|
require "green_monkey/ext/action_view"
|
13
14
|
require "green_monkey/ext/haml"
|
14
15
|
require "green_monkey/ext/mida"
|
data/lib/green_monkey.rb
CHANGED
@@ -1,3 +1,33 @@
|
|
1
1
|
module GreenMonkey
|
2
|
-
|
2
|
+
if defined? Rails
|
3
|
+
require 'green_monkey/railtie'
|
4
|
+
else
|
5
|
+
require "green_monkey/ext/mida"
|
6
|
+
require "green_monkey/ext/haml" if defined? Haml
|
7
|
+
|
8
|
+
if defined? ActiveModel
|
9
|
+
require "green_monkey/ext/active_model"
|
10
|
+
ActiveModel::Dirty.send :include, GreenMonkey::ModelHelpers
|
11
|
+
end
|
12
|
+
|
13
|
+
if defined? ActiveRecord
|
14
|
+
require "green_monkey/ext/active_model"
|
15
|
+
ActiveRecord::Base.send :include, GreenMonkey::ModelHelpers
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
if defined? ActionView
|
20
|
+
require "green_monkey/ext/action_view"
|
21
|
+
require 'green_monkey/ext/view_helper'
|
22
|
+
ActionView::Base.send :include, GreenMonkey::ViewHelper
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
if defined?(Sinatra)
|
27
|
+
require 'green_monkey/ext/view_helper'
|
28
|
+
Sinatra.helpers do
|
29
|
+
include ActionView::Helpers::TagHelper if defined?(ActionView)
|
30
|
+
include GreenMonkey::ViewHelper
|
31
|
+
end
|
32
|
+
end
|
3
33
|
end
|
data/sinatra_app/Gemfile
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
GIT
|
2
|
+
remote: git://github.com/Paxa/chronic_duration.git
|
3
|
+
revision: 8c0d0e101bdbaf2b2299f33e7bfa880b0885a017
|
4
|
+
ref: 8c0d0e101b
|
5
|
+
specs:
|
6
|
+
chronic_duration (0.9.6)
|
7
|
+
numerizer (~> 0.1.1)
|
8
|
+
|
9
|
+
PATH
|
10
|
+
remote: ../
|
11
|
+
specs:
|
12
|
+
green_monkey (0.1.2)
|
13
|
+
chronic_duration
|
14
|
+
haml (>= 3.1.0)
|
15
|
+
mida_vocabulary (>= 0.1)
|
16
|
+
|
17
|
+
GEM
|
18
|
+
remote: http://rubygems.org/
|
19
|
+
specs:
|
20
|
+
actionpack (3.2.2)
|
21
|
+
activemodel (= 3.2.2)
|
22
|
+
activesupport (= 3.2.2)
|
23
|
+
builder (~> 3.0.0)
|
24
|
+
erubis (~> 2.7.0)
|
25
|
+
journey (~> 1.0.1)
|
26
|
+
rack (~> 1.4.0)
|
27
|
+
rack-cache (~> 1.1)
|
28
|
+
rack-test (~> 0.6.1)
|
29
|
+
sprockets (~> 2.1.2)
|
30
|
+
activemodel (3.2.2)
|
31
|
+
activesupport (= 3.2.2)
|
32
|
+
builder (~> 3.0.0)
|
33
|
+
activesupport (3.2.2)
|
34
|
+
i18n (~> 0.6)
|
35
|
+
multi_json (~> 1.0)
|
36
|
+
blankslate (2.1.2.4)
|
37
|
+
builder (3.0.0)
|
38
|
+
erubis (2.7.0)
|
39
|
+
haml (3.1.4)
|
40
|
+
hike (1.2.1)
|
41
|
+
i18n (0.6.0)
|
42
|
+
journey (1.0.3)
|
43
|
+
mida_vocabulary (0.1)
|
44
|
+
blankslate
|
45
|
+
multi_json (1.1.0)
|
46
|
+
numerizer (0.1.1)
|
47
|
+
rack (1.4.1)
|
48
|
+
rack-cache (1.1)
|
49
|
+
rack (>= 0.4)
|
50
|
+
rack-protection (1.2.0)
|
51
|
+
rack
|
52
|
+
rack-test (0.6.1)
|
53
|
+
rack (>= 1.0)
|
54
|
+
sinatra (1.3.2)
|
55
|
+
rack (~> 1.3, >= 1.3.6)
|
56
|
+
rack-protection (~> 1.2)
|
57
|
+
tilt (~> 1.3, >= 1.3.3)
|
58
|
+
sprockets (2.1.2)
|
59
|
+
hike (~> 1.2)
|
60
|
+
rack (~> 1.0)
|
61
|
+
tilt (~> 1.1, != 1.3.0)
|
62
|
+
tilt (1.3.3)
|
63
|
+
|
64
|
+
PLATFORMS
|
65
|
+
ruby
|
66
|
+
|
67
|
+
DEPENDENCIES
|
68
|
+
actionpack
|
69
|
+
chronic_duration!
|
70
|
+
green_monkey!
|
71
|
+
sinatra
|
data/sinatra_app/app.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
|
5
|
+
require 'action_view'
|
6
|
+
require 'sinatra'
|
7
|
+
require 'green_monkey'
|
8
|
+
require 'ostruct'
|
9
|
+
|
10
|
+
|
11
|
+
get '/' do
|
12
|
+
@post = OpenStruct.new(
|
13
|
+
html_schema_type: Mida(:BlogPosting),
|
14
|
+
id: 5,
|
15
|
+
title: 'Hello world',
|
16
|
+
body: 'Sinatra is a DSL for quickly creating web applications in Ruby with minimal effort',
|
17
|
+
created_at: Time.parse('10-feb-2012')
|
18
|
+
)
|
19
|
+
erb :index
|
20
|
+
end
|
21
|
+
|
22
|
+
__END__
|
23
|
+
|
24
|
+
@@ index
|
25
|
+
<DOCTYPE html>
|
26
|
+
<html>
|
27
|
+
<head></head>
|
28
|
+
<body>
|
29
|
+
<article <%= mida_scope(@post) %>>
|
30
|
+
<a href="/posts/<%= @post.id%>" itemprop="url">
|
31
|
+
<h3 itemprop="name"><%= @post.title %></h3>
|
32
|
+
</a>
|
33
|
+
|
34
|
+
<div class="post_body" itemprop="articleBody"><%= @post.body %></div>
|
35
|
+
<%= time_tag @post.created_at, itemprop: 'datePublished' %>
|
36
|
+
</article>
|
37
|
+
</body>
|
38
|
+
</html>
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'haml'
|
5
|
+
require 'sinatra'
|
6
|
+
require 'action_view' # for time_tag support
|
7
|
+
require 'green_monkey'
|
8
|
+
|
9
|
+
require 'ostruct'
|
10
|
+
|
11
|
+
get '/' do
|
12
|
+
@post = OpenStruct.new(
|
13
|
+
html_schema_type: Mida(:BlogPosting),
|
14
|
+
id: 5,
|
15
|
+
title: 'Hello world',
|
16
|
+
body: 'Sinatra is a DSL for quickly creating web applications in Ruby with minimal effort',
|
17
|
+
created_at: Time.parse('10-feb-2012')
|
18
|
+
)
|
19
|
+
haml :index
|
20
|
+
end
|
21
|
+
|
22
|
+
__END__
|
23
|
+
|
24
|
+
@@ index
|
25
|
+
!!! 5
|
26
|
+
%html
|
27
|
+
%head
|
28
|
+
%body
|
29
|
+
%article[@post]
|
30
|
+
%a[:url]{:href => "/posts/#{@post.id}"}
|
31
|
+
%h3[:name]>= @post.title
|
32
|
+
.post_body[:articleBody]= @post.body
|
33
|
+
= time_tag @post.created_at, itemprop: 'datePublished'
|
File without changes
|
data/spec/action_view_spec.rb
CHANGED
@@ -5,11 +5,35 @@ $t = 0
|
|
5
5
|
|
6
6
|
describe "ActionView hacks" do
|
7
7
|
include TestInlineRenderer
|
8
|
-
|
8
|
+
|
9
9
|
it "should works with stylesheet_link_tag" do
|
10
|
-
|
11
|
-
str = render_haml(tpl)
|
10
|
+
str = render_haml "= stylesheet_link_tag 'application'"
|
12
11
|
|
13
12
|
str.should =~ %r{link.+href="/stylesheets/application.css.*"}
|
14
13
|
end
|
14
|
+
|
15
|
+
if Rails.version =~ /^3\.[12].*/
|
16
|
+
it "should work with data- attributes and nested hashes" do
|
17
|
+
str = render_haml('= link_to "An", ?#, data: data_hash', data_hash: {a: 1, b: '2', c: 0.111}).gsub(?', ?")
|
18
|
+
|
19
|
+
str.should =~ /data\-a="1"/
|
20
|
+
str.should =~ /data\-b="2"/
|
21
|
+
str.should =~ /data\-c="0.111"/
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should make itemscope as boolean attribute" do
|
26
|
+
str = render_haml('= tag ?p, itemscope: true')
|
27
|
+
str.should =~ %r{<p\s+itemscope\s*/?>}
|
28
|
+
end
|
29
|
+
|
30
|
+
it "haml should render itemscope as boolean attribute" do
|
31
|
+
str = render_haml('%p{itemscope: true}')
|
32
|
+
str.should =~ %r{<p\s+itemscope\s*/?>}
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should make breadcrumb link" do
|
36
|
+
str = render_haml('= breadcrumb_link_to("Home", "/")')
|
37
|
+
str.index('http://data-vocabulary.org/Breadcrumb').should_not == nil
|
38
|
+
end
|
15
39
|
end
|
data/spec/haml_spec.rb
CHANGED
@@ -72,5 +72,19 @@ describe "Haml generation" do
|
|
72
72
|
str = render_haml("= time_tag_interval(*time, :format => :short)", time: time)
|
73
73
|
str.should =~ /<time.+datetime=.?#{Regexp.escape time[0].iso8601}\/P6DT6H/
|
74
74
|
end
|
75
|
+
|
76
|
+
it "should add class from model" do
|
77
|
+
user = User.create
|
78
|
+
tpl = "%article.person[user]"
|
79
|
+
str = render_haml(tpl, user: user)
|
80
|
+
html_class = str.match(/class=['"]([\w\s]+)['"]/)[1]
|
81
|
+
html_class.should =~ /person/
|
82
|
+
html_class.should =~ /user/
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should make itemscope as boolean attribute" do
|
86
|
+
str = render_haml("%div{:itemscope => true}")
|
87
|
+
str.should =~ %r{<div\s+itemscope\s*/?>}
|
88
|
+
end
|
75
89
|
end
|
76
90
|
end
|
data/spec/post.haml
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: green_monkey
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,33 +9,27 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-04-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
16
|
-
requirement:
|
15
|
+
name: haml
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 3.
|
21
|
+
version: 3.1.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
25
|
-
- !ruby/object:Gem::Dependency
|
26
|
-
name: haml
|
27
|
-
requirement: &2157555460 !ruby/object:Gem::Requirement
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
25
|
none: false
|
29
26
|
requirements:
|
30
27
|
- - ! '>='
|
31
28
|
- !ruby/object:Gem::Version
|
32
29
|
version: 3.1.0
|
33
|
-
type: :runtime
|
34
|
-
prerelease: false
|
35
|
-
version_requirements: *2157555460
|
36
30
|
- !ruby/object:Gem::Dependency
|
37
31
|
name: mida_vocabulary
|
38
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
39
33
|
none: false
|
40
34
|
requirements:
|
41
35
|
- - ! '>='
|
@@ -43,10 +37,15 @@ dependencies:
|
|
43
37
|
version: '0.1'
|
44
38
|
type: :runtime
|
45
39
|
prerelease: false
|
46
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0.1'
|
47
46
|
- !ruby/object:Gem::Dependency
|
48
47
|
name: chronic_duration
|
49
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
50
49
|
none: false
|
51
50
|
requirements:
|
52
51
|
- - ! '>='
|
@@ -54,10 +53,15 @@ dependencies:
|
|
54
53
|
version: '0'
|
55
54
|
type: :runtime
|
56
55
|
prerelease: false
|
57
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
58
62
|
- !ruby/object:Gem::Dependency
|
59
63
|
name: bundler
|
60
|
-
requirement:
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
61
65
|
none: false
|
62
66
|
requirements:
|
63
67
|
- - ! '>='
|
@@ -65,10 +69,15 @@ dependencies:
|
|
65
69
|
version: 1.0.0
|
66
70
|
type: :development
|
67
71
|
prerelease: false
|
68
|
-
version_requirements:
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.0.0
|
69
78
|
- !ruby/object:Gem::Dependency
|
70
79
|
name: rspec
|
71
|
-
requirement:
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
72
81
|
none: false
|
73
82
|
requirements:
|
74
83
|
- - ! '>='
|
@@ -76,10 +85,31 @@ dependencies:
|
|
76
85
|
version: 2.7.0
|
77
86
|
type: :development
|
78
87
|
prerelease: false
|
79
|
-
version_requirements:
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 2.7.0
|
80
94
|
- !ruby/object:Gem::Dependency
|
81
95
|
name: rspec-rails
|
82
|
-
requirement:
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: mida
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
83
113
|
none: false
|
84
114
|
requirements:
|
85
115
|
- - ! '>='
|
@@ -87,10 +117,15 @@ dependencies:
|
|
87
117
|
version: '0'
|
88
118
|
type: :development
|
89
119
|
prerelease: false
|
90
|
-
version_requirements:
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
91
126
|
- !ruby/object:Gem::Dependency
|
92
127
|
name: sqlite3
|
93
|
-
requirement:
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
94
129
|
none: false
|
95
130
|
requirements:
|
96
131
|
- - ! '>='
|
@@ -98,7 +133,12 @@ dependencies:
|
|
98
133
|
version: '0'
|
99
134
|
type: :development
|
100
135
|
prerelease: false
|
101
|
-
version_requirements:
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
102
142
|
description: It hacks Rails and Haml
|
103
143
|
email:
|
104
144
|
- pavel.evst@gmail.com
|
@@ -112,8 +152,8 @@ files:
|
|
112
152
|
- Gemfile
|
113
153
|
- Gemfile.haml-edge
|
114
154
|
- Gemfile.lock
|
115
|
-
- Gemfile.rails-3.0
|
116
|
-
- Gemfile.rails-3.1
|
155
|
+
- Gemfile.rails-3.0
|
156
|
+
- Gemfile.rails-3.1
|
117
157
|
- Gemfile.rails-3.2
|
118
158
|
- README.md
|
119
159
|
- Rakefile
|
@@ -125,6 +165,11 @@ files:
|
|
125
165
|
- lib/green_monkey/ext/mida.rb
|
126
166
|
- lib/green_monkey/ext/view_helper.rb
|
127
167
|
- lib/green_monkey/railtie.rb
|
168
|
+
- sinatra_app/Gemfile
|
169
|
+
- sinatra_app/Gemfile.lock
|
170
|
+
- sinatra_app/app.rb
|
171
|
+
- sinatra_app/app_haml.rb
|
172
|
+
- sinatra_app/config.ru
|
128
173
|
- spec/action_view_spec.rb
|
129
174
|
- spec/haml_spec.rb
|
130
175
|
- spec/mida_spec.rb
|
@@ -155,7 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
155
200
|
version: 1.2.0
|
156
201
|
requirements: []
|
157
202
|
rubyforge_project:
|
158
|
-
rubygems_version: 1.8.
|
203
|
+
rubygems_version: 1.8.22
|
159
204
|
signing_key:
|
160
205
|
specification_version: 3
|
161
206
|
summary: Rails and Haml microdata layout helpers
|
data/Gemfile.rails-3.0.11
DELETED