pakyow-presenter 0.8rc1 → 0.8.rc4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/pakyow-presenter/lib/pakyow-presenter.rb +2 -1
- data/pakyow-presenter/lib/presenter/attributes.rb +128 -35
- data/pakyow-presenter/lib/presenter/base.rb +8 -4
- data/pakyow-presenter/lib/presenter/binder.rb +62 -30
- data/pakyow-presenter/lib/presenter/binder_set.rb +95 -0
- data/pakyow-presenter/lib/presenter/config/presenter.rb +61 -0
- data/pakyow-presenter/lib/presenter/doc_helpers.rb +70 -0
- data/pakyow-presenter/lib/presenter/exceptions.rb +7 -0
- data/pakyow-presenter/lib/presenter/ext/app.rb +32 -0
- data/pakyow-presenter/lib/presenter/helpers.rb +4 -5
- data/pakyow-presenter/lib/presenter/page.rb +126 -0
- data/pakyow-presenter/lib/presenter/partial.rb +24 -0
- data/pakyow-presenter/lib/presenter/presenter.rb +120 -187
- data/pakyow-presenter/lib/presenter/template.rb +79 -0
- data/pakyow-presenter/lib/presenter/view.rb +255 -300
- data/pakyow-presenter/lib/presenter/view_collection.rb +55 -39
- data/pakyow-presenter/lib/presenter/view_store.rb +174 -0
- metadata +43 -32
- data/pakyow-presenter/lib/presenter/bindings.rb +0 -103
- data/pakyow-presenter/lib/presenter/configuration/base.rb +0 -12
- data/pakyow-presenter/lib/presenter/configuration/presenter.rb +0 -45
- data/pakyow-presenter/lib/presenter/lazy_view.rb +0 -42
- data/pakyow-presenter/lib/presenter/view_context.rb +0 -20
- data/pakyow-presenter/lib/presenter/view_lookup_store.rb +0 -220
@@ -1,42 +0,0 @@
|
|
1
|
-
module Pakyow
|
2
|
-
module Presenter
|
3
|
-
class LazyView < View
|
4
|
-
|
5
|
-
def to_html(*args)
|
6
|
-
Pakyow.app.presenter.ensure_root_view_built
|
7
|
-
super
|
8
|
-
end
|
9
|
-
|
10
|
-
def add_content_to_container(*args)
|
11
|
-
Pakyow.app.presenter.ensure_root_view_built
|
12
|
-
super
|
13
|
-
end
|
14
|
-
|
15
|
-
def find(*args)
|
16
|
-
Pakyow.app.presenter.ensure_root_view_built
|
17
|
-
super
|
18
|
-
end
|
19
|
-
|
20
|
-
def repeat_for(*args, &block)
|
21
|
-
Pakyow.app.presenter.ensure_root_view_built
|
22
|
-
super
|
23
|
-
end
|
24
|
-
|
25
|
-
def reset_container(*args)
|
26
|
-
Pakyow.app.presenter.ensure_root_view_built
|
27
|
-
super
|
28
|
-
end
|
29
|
-
|
30
|
-
def title=(*args)
|
31
|
-
Pakyow.app.presenter.ensure_root_view_built
|
32
|
-
super
|
33
|
-
end
|
34
|
-
|
35
|
-
def bind(*args)
|
36
|
-
Pakyow.app.presenter.ensure_root_view_built
|
37
|
-
super
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
module Pakyow
|
2
|
-
module Presenter
|
3
|
-
class ViewContext
|
4
|
-
include Helpers
|
5
|
-
|
6
|
-
def initialize(context)
|
7
|
-
@context = context
|
8
|
-
self
|
9
|
-
end
|
10
|
-
|
11
|
-
def context
|
12
|
-
@context
|
13
|
-
end
|
14
|
-
|
15
|
-
def method_missing(method, *args)
|
16
|
-
Pakyow.app.presenter.current_context.send(method, *args)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,220 +0,0 @@
|
|
1
|
-
module Pakyow
|
2
|
-
module Presenter
|
3
|
-
class ViewLookupStore
|
4
|
-
|
5
|
-
# @view_store is a hash structured as:
|
6
|
-
# {
|
7
|
-
# :view_dirs => {
|
8
|
-
# "/route" => {
|
9
|
-
# :root_view => "path/to/root/view",
|
10
|
-
# :views => {
|
11
|
-
# "view1_name" => "path/to/view1",
|
12
|
-
# "view2_name" => "path/to/view2"
|
13
|
-
# }
|
14
|
-
# },
|
15
|
-
# "/route/sub" => {
|
16
|
-
# :root_view => "path/to/root/view",
|
17
|
-
# :views => {
|
18
|
-
# "view1_name" => "path/to/view1",
|
19
|
-
# "view2_name" => "path/to/view2"
|
20
|
-
# }
|
21
|
-
# }
|
22
|
-
# },
|
23
|
-
# :abstract_paths => {
|
24
|
-
# "/abstract/path/file.html" => {:real_path => "/abstract.root1/path/file.html", :file_or_dir => :file},
|
25
|
-
# "/some/other/path" => {:real_path => "/some/other.root1/path.root2", :file_or_dir => :dir}
|
26
|
-
# }
|
27
|
-
# }
|
28
|
-
# This takes into account that a view directory may have a .root suffix.
|
29
|
-
# This not only determines the root view for that route (and sub-routes) but that
|
30
|
-
# the route doesn't include the suffix but the path to a view does
|
31
|
-
|
32
|
-
attr_reader(:view_dir)
|
33
|
-
|
34
|
-
def initialize(view_dir)
|
35
|
-
@view_store = {:view_dirs => {}, :abstract_paths => {}}
|
36
|
-
return unless File.exist?(view_dir)
|
37
|
-
|
38
|
-
@view_dir = view_dir
|
39
|
-
|
40
|
-
# wack the ./ at the beginning if it's there
|
41
|
-
view_dir = view_dir.sub(/^\.\//,'')
|
42
|
-
|
43
|
-
# making this a variable in case we change whether we store relative or absolute paths to views
|
44
|
-
absolute_path_prefix = view_dir # set to '' to store absolute paths
|
45
|
-
|
46
|
-
default_views = {} # view_basename => path_to_view.html
|
47
|
-
if File.exist?(view_dir) then
|
48
|
-
default_root_view_file_path = "#{absolute_path_prefix}/#{Configuration::Presenter.default_view}"
|
49
|
-
# The logic depends on this traversing top down
|
50
|
-
DirUtils.walk_dir(view_dir) { |vpath|
|
51
|
-
if File.directory?(vpath)
|
52
|
-
parent,route = pakyow_path_to_route_and_parent(vpath, view_dir, :dir)
|
53
|
-
# root_view is same as parent unless this route overrides it
|
54
|
-
# views are a copy of parent views
|
55
|
-
route_root_path = @view_store[:view_dirs][parent] ? @view_store[:view_dirs][parent][:root_view] : default_root_view_file_path
|
56
|
-
route_views = @view_store[:view_dirs][parent] ? deep_hash_clone(@view_store[:view_dirs][parent][:views]) : deep_hash_clone(default_views)
|
57
|
-
# see if this route overrides root_view
|
58
|
-
route_part, root_part = StringUtils.split_at_last_dot(vpath)
|
59
|
-
if root_part && root_part.include?('/')
|
60
|
-
route_part, root_part = vpath, nil
|
61
|
-
end
|
62
|
-
if root_part
|
63
|
-
if File.exist?("#{vpath}/#{root_part}.html")
|
64
|
-
route_root_path = "#{vpath}/#{root_part}.html".sub(absolute_path_prefix, '')
|
65
|
-
elsif route_views[root_part]
|
66
|
-
route_root_path = route_views[root_part]
|
67
|
-
else
|
68
|
-
if Configuration::Base.app.dev_mode == true
|
69
|
-
Log.warn("Root view #{root_part} referenced in #{vpath.sub(absolute_path_prefix, '')} was not found.")
|
70
|
-
else
|
71
|
-
Log.error("Root view #{root_part} referenced in #{vpath.sub(absolute_path_prefix, '')} was not found.")
|
72
|
-
raise "Root view #{root_part} referenced in #{vpath.sub(absolute_path_prefix, '')} was not found."
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
@view_store[:view_dirs][route] =
|
77
|
-
{
|
78
|
-
:root_view => route_root_path,
|
79
|
-
:views => route_views
|
80
|
-
}
|
81
|
-
# set the abstract path for this dir
|
82
|
-
if route == '/'
|
83
|
-
r_p = '/'
|
84
|
-
else
|
85
|
-
r_p = File.join(@view_dir, vpath.sub(absolute_path_prefix, ''))
|
86
|
-
end
|
87
|
-
@view_store[:abstract_paths][route] = {:real_path => r_p, :file_or_dir => :dir}
|
88
|
-
# duplicate real path under routes permuted with leading/trailing slash
|
89
|
-
permute_route(route).each { |r| @view_store[:abstract_paths][r] = {:real_path => r_p, :file_or_dir => :dir} } unless route == '/'
|
90
|
-
else
|
91
|
-
# files here are direct overrides of the route's views
|
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('/','')
|
95
|
-
view_key = File.basename(vpath,".*")
|
96
|
-
unless @view_store[:view_dirs][route]
|
97
|
-
@view_store[:view_dirs][route] = deep_hash_clone(@view_store[:view_dirs][parent])
|
98
|
-
end
|
99
|
-
@view_store[:view_dirs][route][:views][view_key] = route_without_leading_slash
|
100
|
-
# see if view overrides the root view
|
101
|
-
if File.basename(@view_store[:view_dirs][route][:root_view],".*") == view_key
|
102
|
-
@view_store[:view_dirs][route][:root_view] = route_without_leading_slash
|
103
|
-
end
|
104
|
-
# set the abstract path for this file
|
105
|
-
# duplicating real path under route without the leading slash
|
106
|
-
r_p = File.join(@view_dir, vpath.sub(absolute_path_prefix, ''))
|
107
|
-
if route == '/'
|
108
|
-
@view_store[:abstract_paths]["/#{File.basename(vpath)}"] = {:real_path => r_p, :file_or_dir => :file}
|
109
|
-
@view_store[:abstract_paths][File.basename(vpath)] = {:real_path => r_p, :file_or_dir => :file}
|
110
|
-
else
|
111
|
-
@view_store[:abstract_paths][route_with_leading_slash] = {:real_path => r_p, :file_or_dir => :file}
|
112
|
-
@view_store[:abstract_paths][route_without_leading_slash] = {:real_path => r_p, :file_or_dir => :file}
|
113
|
-
end
|
114
|
-
end
|
115
|
-
}
|
116
|
-
end
|
117
|
-
|
118
|
-
# adjust @view_store '.../index' entries to override the parent
|
119
|
-
@view_store[:view_dirs].each_pair {|route,info|
|
120
|
-
next unless File.basename(route) == "index"
|
121
|
-
parent = File.dirname(route)
|
122
|
-
@view_store[:view_dirs][parent] = info
|
123
|
-
}
|
124
|
-
# adjust @view_store entries to have a '.../index' counterpart where missing
|
125
|
-
index_counterparts = {}
|
126
|
-
@view_store[:view_dirs].each_pair {|route,info|
|
127
|
-
next if File.basename(route) == "index" || @view_store[:view_dirs]["#{route}/index"]
|
128
|
-
if route == "/"
|
129
|
-
index_counterparts["/index"] = info
|
130
|
-
else
|
131
|
-
index_counterparts["#{route}/index"] = info
|
132
|
-
end
|
133
|
-
}
|
134
|
-
index_counterparts.each_pair { |route,info|
|
135
|
-
@view_store[:view_dirs][route] = info
|
136
|
-
}
|
137
|
-
# Duplicate the info for each combination of route with and without a leading and ending slash
|
138
|
-
# All current keys have a leading slash and no trailing slash
|
139
|
-
slash_permutations = {}
|
140
|
-
@view_store[:view_dirs].each_pair {|route0,info|
|
141
|
-
unless route0 == '/' then
|
142
|
-
route1, route2, route3 = permute_route(route0)
|
143
|
-
slash_permutations[route1] = info
|
144
|
-
slash_permutations[route2] = info
|
145
|
-
slash_permutations[route3] = info
|
146
|
-
end
|
147
|
-
}
|
148
|
-
slash_permutations.each_pair { |route,info|
|
149
|
-
@view_store[:view_dirs][route] = info
|
150
|
-
}
|
151
|
-
end
|
152
|
-
|
153
|
-
def view_info(route = nil)
|
154
|
-
if route
|
155
|
-
return @view_store[:view_dirs][route]
|
156
|
-
else
|
157
|
-
return @view_store[:view_dirs]
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
def real_path_info(abstract_path = nil)
|
162
|
-
if abstract_path then
|
163
|
-
@view_store[:abstract_paths][abstract_path]
|
164
|
-
else
|
165
|
-
@view_store[:abstract_paths]
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
def real_path(abstract_path)
|
170
|
-
@view_store[:abstract_paths][abstract_path][:real_path] if @view_store[:abstract_paths][abstract_path]
|
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
|
176
|
-
|
177
|
-
private
|
178
|
-
|
179
|
-
# path can be of the form prefix_path/this/route.root1/overrides/some.root2/root
|
180
|
-
# returns the path without the .root_view parts
|
181
|
-
def pakyow_path_to_route_and_parent(path, path_prefix, file_or_dir)
|
182
|
-
return "","/" if path == path_prefix
|
183
|
-
route_path = path.sub("#{path_prefix}/", "")
|
184
|
-
unless route_path.include?("/")
|
185
|
-
return "","/" if :file == file_or_dir
|
186
|
-
return "/","/#{StringUtils.split_at_last_dot(route_path)[0]}"
|
187
|
-
end
|
188
|
-
route = ""
|
189
|
-
parent = ""
|
190
|
-
segments = route_path.split('/')
|
191
|
-
segments.each_with_index {|s,i|
|
192
|
-
next if (i >= segments.length-1 && :file == file_or_dir)
|
193
|
-
route_part = StringUtils.split_at_last_dot(s)[0]
|
194
|
-
route << "/#{route_part}"
|
195
|
-
next if (i >= segments.length-2 && :file == file_or_dir) || (i >= segments.length-1 && :dir == file_or_dir)
|
196
|
-
parent << "/#{route_part}"
|
197
|
-
}
|
198
|
-
parent = "/" if parent == ""
|
199
|
-
return parent,route
|
200
|
-
end
|
201
|
-
|
202
|
-
# Gonna just use Marshal for now.
|
203
|
-
# Can change later if needed since we only need to work
|
204
|
-
# on hashes of symbols, strings and hashes.
|
205
|
-
def deep_hash_clone(h)
|
206
|
-
Marshal.load(Marshal.dump(h))
|
207
|
-
end
|
208
|
-
|
209
|
-
# Takes a route with a leading slash and no trailing slash (/route) and
|
210
|
-
# returns the three other permutations (/route/, route/, and route).
|
211
|
-
def permute_route(route0)
|
212
|
-
route3 = route0.sub('/','')
|
213
|
-
route2 = "#{route3}/"
|
214
|
-
route1 = "#{route0}/"
|
215
|
-
return route1,route2,route3
|
216
|
-
end
|
217
|
-
|
218
|
-
end
|
219
|
-
end
|
220
|
-
end
|