pakyow-presenter 0.7.2 → 0.8rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/pakyow-presenter/lib/presenter/attributes.rb +92 -0
- data/pakyow-presenter/lib/presenter/base.rb +3 -1
- data/pakyow-presenter/lib/presenter/binder.rb +6 -23
- data/pakyow-presenter/lib/presenter/bindings.rb +103 -0
- data/pakyow-presenter/lib/presenter/configuration/presenter.rb +16 -3
- data/pakyow-presenter/lib/presenter/helpers.rb +8 -0
- data/pakyow-presenter/lib/presenter/presenter.rb +102 -76
- data/pakyow-presenter/lib/presenter/view.rb +441 -244
- data/pakyow-presenter/lib/presenter/view_collection.rb +187 -0
- data/pakyow-presenter/lib/presenter/view_lookup_store.rb +10 -6
- metadata +59 -76
- data/pakyow-presenter/lib/presenter/views.rb +0 -112
@@ -0,0 +1,187 @@
|
|
1
|
+
module Pakyow
|
2
|
+
module Presenter
|
3
|
+
class ViewCollection
|
4
|
+
include Enumerable
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@views = []
|
8
|
+
end
|
9
|
+
|
10
|
+
def each
|
11
|
+
@views.each { |v| yield(v) }
|
12
|
+
end
|
13
|
+
|
14
|
+
def attributes(*args)
|
15
|
+
collection = AttributesCollection.new
|
16
|
+
self.each{|v| collection << v.attributes}
|
17
|
+
return collection
|
18
|
+
end
|
19
|
+
|
20
|
+
alias :attrs :attributes
|
21
|
+
|
22
|
+
def remove
|
23
|
+
self.each {|e| e.remove}
|
24
|
+
end
|
25
|
+
|
26
|
+
alias :delete :remove
|
27
|
+
|
28
|
+
# SEE COMMENT IN VIEW
|
29
|
+
# def add_class(val)
|
30
|
+
# self.each {|e| e.add_class(val)}
|
31
|
+
# end
|
32
|
+
|
33
|
+
# SEE COMMENT IN VIEW
|
34
|
+
# def remove_class(val)
|
35
|
+
# self.each {|e| e.remove_class(val)}
|
36
|
+
# end
|
37
|
+
|
38
|
+
def clear
|
39
|
+
self.each {|e| e.clear}
|
40
|
+
end
|
41
|
+
|
42
|
+
def text
|
43
|
+
self.map { |v| v.text }
|
44
|
+
end
|
45
|
+
|
46
|
+
def content
|
47
|
+
self.map { |v| v.content }
|
48
|
+
end
|
49
|
+
|
50
|
+
alias :html :content
|
51
|
+
|
52
|
+
def content=(content)
|
53
|
+
self.each {|e| e.content = content}
|
54
|
+
end
|
55
|
+
|
56
|
+
alias :html= :content=
|
57
|
+
|
58
|
+
def to_html
|
59
|
+
self.map { |v| v.to_html }.join('')
|
60
|
+
end
|
61
|
+
|
62
|
+
alias :to_s :to_html
|
63
|
+
|
64
|
+
def append(content)
|
65
|
+
self.each {|e| e.append(content)}
|
66
|
+
end
|
67
|
+
|
68
|
+
alias :render :append
|
69
|
+
|
70
|
+
def <<(val)
|
71
|
+
if val.is_a? View
|
72
|
+
@views << val
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def [](i)
|
77
|
+
@views[i]
|
78
|
+
end
|
79
|
+
|
80
|
+
def length
|
81
|
+
@views.length
|
82
|
+
end
|
83
|
+
|
84
|
+
def scope(name)
|
85
|
+
views = ViewCollection.new
|
86
|
+
self.each{|v|
|
87
|
+
next unless svs = v.scope(name)
|
88
|
+
svs.each{|sv| views << sv}
|
89
|
+
}
|
90
|
+
|
91
|
+
views
|
92
|
+
end
|
93
|
+
|
94
|
+
# call-seq:
|
95
|
+
# with {|view| block}
|
96
|
+
#
|
97
|
+
# Creates a context in which view manipulations can be performed.
|
98
|
+
#
|
99
|
+
# Unlike previous versions, the context can only be referenced by the
|
100
|
+
# block argument. No `context` method will be available.s
|
101
|
+
#
|
102
|
+
def with
|
103
|
+
yield(self)
|
104
|
+
end
|
105
|
+
|
106
|
+
# call-seq:
|
107
|
+
# for {|view, datum| block}
|
108
|
+
#
|
109
|
+
# Yields a view and its matching dataum. Datums are yielded until
|
110
|
+
# no more views or data is available. For the ViewCollection case, this
|
111
|
+
# means the block will be yielded self.length times.
|
112
|
+
#
|
113
|
+
# (this is basically Bret's `map` function)
|
114
|
+
#
|
115
|
+
def for(data, &block)
|
116
|
+
data = [data] unless data.instance_of?(Array)
|
117
|
+
self.each_with_index { |v,i|
|
118
|
+
break unless datum = data[i]
|
119
|
+
block.call(v, datum)
|
120
|
+
}
|
121
|
+
end
|
122
|
+
|
123
|
+
# call-seq:
|
124
|
+
# match(data) => ViewCollection
|
125
|
+
#
|
126
|
+
# Returns a ViewCollection object that has been manipulated to match the data.
|
127
|
+
# For the ViewCollection case, the returned ViewCollection collection will consist n copies
|
128
|
+
# of self[data index] || self[-1], where n = data.length.
|
129
|
+
#
|
130
|
+
def match(data)
|
131
|
+
data = [data] unless data.instance_of?(Array)
|
132
|
+
|
133
|
+
views = ViewCollection.new
|
134
|
+
data.each_with_index {|datum,i|
|
135
|
+
unless v = self[i]
|
136
|
+
|
137
|
+
# we're out of views, so use the last one
|
138
|
+
v = self[-1]
|
139
|
+
end
|
140
|
+
|
141
|
+
d_v = v.doc.dup
|
142
|
+
v.doc.before(d_v)
|
143
|
+
|
144
|
+
new_v = View.new(d_v)
|
145
|
+
|
146
|
+
# find binding subset (keeps us from refinding)
|
147
|
+
new_v.bindings = v.bindings
|
148
|
+
|
149
|
+
views << new_v
|
150
|
+
}
|
151
|
+
|
152
|
+
self.remove
|
153
|
+
views
|
154
|
+
end
|
155
|
+
|
156
|
+
# call-seq:
|
157
|
+
# repeat(data) {|view, datum| block}
|
158
|
+
#
|
159
|
+
# Matches self to data and yields a view/datum pair.
|
160
|
+
#
|
161
|
+
def repeat(data, &block)
|
162
|
+
self.match(data).for(data, &block)
|
163
|
+
end
|
164
|
+
|
165
|
+
# call-seq:
|
166
|
+
# bind(data)
|
167
|
+
#
|
168
|
+
# Binds data across existing scopes.
|
169
|
+
#
|
170
|
+
def bind(data, bindings = nil, &block)
|
171
|
+
self.for(data) {|view, datum|
|
172
|
+
view.bind(datum, bindings)
|
173
|
+
yield(view, datum) if block_given?
|
174
|
+
}
|
175
|
+
end
|
176
|
+
|
177
|
+
# call-seq:
|
178
|
+
# apply(data)
|
179
|
+
#
|
180
|
+
# Matches self to data then binds data to the view.
|
181
|
+
#
|
182
|
+
def apply(data, bindings = nil, &block)
|
183
|
+
self.match(data).bind(data, bindings, &block)
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
@@ -82,7 +82,7 @@ module Pakyow
|
|
82
82
|
if route == '/'
|
83
83
|
r_p = '/'
|
84
84
|
else
|
85
|
-
r_p = vpath.sub(absolute_path_prefix, '')
|
85
|
+
r_p = File.join(@view_dir, vpath.sub(absolute_path_prefix, ''))
|
86
86
|
end
|
87
87
|
@view_store[:abstract_paths][route] = {:real_path => r_p, :file_or_dir => :dir}
|
88
88
|
# duplicate real path under routes permuted with leading/trailing slash
|
@@ -90,24 +90,24 @@ module Pakyow
|
|
90
90
|
else
|
91
91
|
# files here are direct overrides of the route's views
|
92
92
|
parent,route = pakyow_path_to_route_and_parent(vpath, view_dir, :file)
|
93
|
+
route_with_leading_slash = "#{route}/#{File.basename(vpath)}"
|
94
|
+
route_without_leading_slash = route_with_leading_slash.sub('/','')
|
93
95
|
view_key = File.basename(vpath,".*")
|
94
96
|
unless @view_store[:view_dirs][route]
|
95
97
|
@view_store[:view_dirs][route] = deep_hash_clone(@view_store[:view_dirs][parent])
|
96
98
|
end
|
97
|
-
@view_store[:view_dirs][route][:views][view_key] =
|
99
|
+
@view_store[:view_dirs][route][:views][view_key] = route_without_leading_slash
|
98
100
|
# see if view overrides the root view
|
99
101
|
if File.basename(@view_store[:view_dirs][route][:root_view],".*") == view_key
|
100
|
-
@view_store[:view_dirs][route][:root_view] =
|
102
|
+
@view_store[:view_dirs][route][:root_view] = route_without_leading_slash
|
101
103
|
end
|
102
104
|
# set the abstract path for this file
|
103
105
|
# duplicating real path under route without the leading slash
|
104
|
-
r_p = vpath.sub(absolute_path_prefix, '')
|
106
|
+
r_p = File.join(@view_dir, vpath.sub(absolute_path_prefix, ''))
|
105
107
|
if route == '/'
|
106
108
|
@view_store[:abstract_paths]["/#{File.basename(vpath)}"] = {:real_path => r_p, :file_or_dir => :file}
|
107
109
|
@view_store[:abstract_paths][File.basename(vpath)] = {:real_path => r_p, :file_or_dir => :file}
|
108
110
|
else
|
109
|
-
route_with_leading_slash = "#{route}/#{File.basename(vpath)}"
|
110
|
-
route_without_leading_slash = route_with_leading_slash.sub('/','')
|
111
111
|
@view_store[:abstract_paths][route_with_leading_slash] = {:real_path => r_p, :file_or_dir => :file}
|
112
112
|
@view_store[:abstract_paths][route_without_leading_slash] = {:real_path => r_p, :file_or_dir => :file}
|
113
113
|
end
|
@@ -169,6 +169,10 @@ module Pakyow
|
|
169
169
|
def real_path(abstract_path)
|
170
170
|
@view_store[:abstract_paths][abstract_path][:real_path] if @view_store[:abstract_paths][abstract_path]
|
171
171
|
end
|
172
|
+
|
173
|
+
def root_path(abstract_path)
|
174
|
+
@view_store[:view_dirs][abstract_path][:root_view] if @view_store[:view_dirs][abstract_path]
|
175
|
+
end
|
172
176
|
|
173
177
|
private
|
174
178
|
|
metadata
CHANGED
@@ -1,127 +1,110 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: pakyow-presenter
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 7
|
9
|
-
- 2
|
10
|
-
version: 0.7.2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.8rc1
|
5
|
+
prerelease: 3
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Bryan Powell
|
14
9
|
- Bret Young
|
15
10
|
autorequire:
|
16
11
|
bindir: bin
|
17
12
|
cert_chain: []
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
- !ruby/object:Gem::Dependency
|
13
|
+
date: 2013-02-11 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
22
16
|
name: pakyow-core
|
23
|
-
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
25
18
|
none: false
|
26
|
-
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
segments:
|
31
|
-
- 0
|
32
|
-
- 7
|
33
|
-
- 2
|
34
|
-
version: 0.7.2
|
19
|
+
requirements:
|
20
|
+
- - '='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.8rc1
|
35
23
|
type: :runtime
|
36
|
-
version_requirements: *id001
|
37
|
-
- !ruby/object:Gem::Dependency
|
38
|
-
name: nokogiri
|
39
24
|
prerelease: false
|
40
|
-
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - '='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: 0.8rc1
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: nokogiri
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
41
34
|
none: false
|
42
|
-
requirements:
|
35
|
+
requirements:
|
43
36
|
- - ~>
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
|
46
|
-
segments:
|
47
|
-
- 1
|
48
|
-
- 5
|
49
|
-
version: "1.5"
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '1.5'
|
50
39
|
type: :runtime
|
51
|
-
version_requirements: *id002
|
52
|
-
- !ruby/object:Gem::Dependency
|
53
|
-
name: shoulda
|
54
40
|
prerelease: false
|
55
|
-
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
56
42
|
none: false
|
57
|
-
requirements:
|
43
|
+
requirements:
|
58
44
|
- - ~>
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.5'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: shoulda
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.11'
|
65
55
|
type: :development
|
66
|
-
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ~>
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '2.11'
|
67
63
|
description: pakyow-presenter
|
68
64
|
email: bryan@metabahn.com
|
69
65
|
executables: []
|
70
|
-
|
71
66
|
extensions: []
|
72
|
-
|
73
67
|
extra_rdoc_files: []
|
74
|
-
|
75
|
-
files:
|
68
|
+
files:
|
76
69
|
- pakyow-presenter/CHANGES
|
77
70
|
- pakyow-presenter/README
|
78
71
|
- pakyow-presenter/MIT-LICENSE
|
79
72
|
- pakyow-presenter/lib/pakyow-presenter.rb
|
73
|
+
- pakyow-presenter/lib/presenter/attributes.rb
|
80
74
|
- pakyow-presenter/lib/presenter/base.rb
|
81
75
|
- pakyow-presenter/lib/presenter/binder.rb
|
76
|
+
- pakyow-presenter/lib/presenter/bindings.rb
|
82
77
|
- pakyow-presenter/lib/presenter/configuration/base.rb
|
83
78
|
- pakyow-presenter/lib/presenter/configuration/presenter.rb
|
84
79
|
- pakyow-presenter/lib/presenter/helpers.rb
|
85
80
|
- pakyow-presenter/lib/presenter/lazy_view.rb
|
86
81
|
- pakyow-presenter/lib/presenter/presenter.rb
|
87
82
|
- pakyow-presenter/lib/presenter/view.rb
|
83
|
+
- pakyow-presenter/lib/presenter/view_collection.rb
|
88
84
|
- pakyow-presenter/lib/presenter/view_context.rb
|
89
85
|
- pakyow-presenter/lib/presenter/view_lookup_store.rb
|
90
|
-
- pakyow-presenter/lib/presenter/views.rb
|
91
86
|
homepage: http://pakyow.com
|
92
87
|
licenses: []
|
93
|
-
|
94
88
|
post_install_message:
|
95
89
|
rdoc_options: []
|
96
|
-
|
97
|
-
require_paths:
|
90
|
+
require_paths:
|
98
91
|
- pakyow-presenter/lib
|
99
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
93
|
none: false
|
101
|
-
requirements:
|
102
|
-
- -
|
103
|
-
- !ruby/object:Gem::Version
|
104
|
-
hash: 57
|
105
|
-
segments:
|
106
|
-
- 1
|
107
|
-
- 8
|
108
|
-
- 7
|
94
|
+
requirements:
|
95
|
+
- - ! '>='
|
96
|
+
- !ruby/object:Gem::Version
|
109
97
|
version: 1.8.7
|
110
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
99
|
none: false
|
112
|
-
requirements:
|
113
|
-
- -
|
114
|
-
- !ruby/object:Gem::Version
|
115
|
-
|
116
|
-
segments:
|
117
|
-
- 0
|
118
|
-
version: "0"
|
100
|
+
requirements:
|
101
|
+
- - ! '>'
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 1.3.1
|
119
104
|
requirements: []
|
120
|
-
|
121
105
|
rubyforge_project: pakyow-presenter
|
122
|
-
rubygems_version: 1.8.
|
106
|
+
rubygems_version: 1.8.23
|
123
107
|
signing_key:
|
124
108
|
specification_version: 3
|
125
109
|
summary: pakyow-presenter
|
126
110
|
test_files: []
|
127
|
-
|
@@ -1,112 +0,0 @@
|
|
1
|
-
module Pakyow
|
2
|
-
module Presenter
|
3
|
-
class Views
|
4
|
-
include Enumerable
|
5
|
-
|
6
|
-
def initialize
|
7
|
-
@views = []
|
8
|
-
end
|
9
|
-
|
10
|
-
def each
|
11
|
-
@views.each { |v| yield(v) }
|
12
|
-
end
|
13
|
-
|
14
|
-
def in_context(&block)
|
15
|
-
ViewContext.new(self).instance_exec(self, &block)
|
16
|
-
end
|
17
|
-
|
18
|
-
def attributes(*args)
|
19
|
-
self.each {|e| e.attributes(*args)}
|
20
|
-
return self
|
21
|
-
end
|
22
|
-
|
23
|
-
def remove
|
24
|
-
self.each {|e| e.remove}
|
25
|
-
end
|
26
|
-
|
27
|
-
alias :delete :remove
|
28
|
-
|
29
|
-
def add_class(val)
|
30
|
-
self.each {|e| e.add_class(val)}
|
31
|
-
end
|
32
|
-
|
33
|
-
def remove_class(val)
|
34
|
-
self.each {|e| e.remove_class(val)}
|
35
|
-
end
|
36
|
-
|
37
|
-
def clear
|
38
|
-
self.each {|e| e.clear}
|
39
|
-
end
|
40
|
-
|
41
|
-
def text
|
42
|
-
self.map { |v| v.text }
|
43
|
-
end
|
44
|
-
|
45
|
-
def content
|
46
|
-
self.map { |v| v.content }
|
47
|
-
end
|
48
|
-
|
49
|
-
alias :html :content
|
50
|
-
|
51
|
-
def content=(content)
|
52
|
-
self.each {|e| e.content = content}
|
53
|
-
end
|
54
|
-
|
55
|
-
alias :html= :content=
|
56
|
-
|
57
|
-
def to_html
|
58
|
-
self.map { |v| v.to_html }.join('')
|
59
|
-
end
|
60
|
-
|
61
|
-
alias :to_s :to_html
|
62
|
-
|
63
|
-
def append(content)
|
64
|
-
self.each {|e| e.append(content)}
|
65
|
-
end
|
66
|
-
|
67
|
-
alias :render :append
|
68
|
-
|
69
|
-
def <<(val)
|
70
|
-
if val.is_a? View
|
71
|
-
@views << val
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
def method_missing(method, *args)
|
76
|
-
if method.to_s.include?('=')
|
77
|
-
self.each {|e| e.send(method, *args)}
|
78
|
-
else
|
79
|
-
self.map {|e| e.send(method, *args)}
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
def class(*args)
|
84
|
-
method_missing(:class, *args)
|
85
|
-
end
|
86
|
-
|
87
|
-
def id
|
88
|
-
method_missing(:id)
|
89
|
-
end
|
90
|
-
|
91
|
-
def repeat_for(objects, opts = {}, &block)
|
92
|
-
first_found = self.first
|
93
|
-
|
94
|
-
# Remove other matches
|
95
|
-
self.drop(1).each {|found| found.remove}
|
96
|
-
|
97
|
-
# Repeat for first match
|
98
|
-
first_found.repeat_for(objects, opts, &block)
|
99
|
-
end
|
100
|
-
|
101
|
-
def bind(object, opts = {})
|
102
|
-
self.each {|e| e.bind(object, opts)}
|
103
|
-
end
|
104
|
-
|
105
|
-
def find(element, &block)
|
106
|
-
views = Views.new
|
107
|
-
self.each {|e| e.find(element, &block).each { |v| views << v }}
|
108
|
-
views
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|