pakyow-presenter 0.8.rc4 → 0.8.0
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.
- checksums.yaml +4 -4
- data/pakyow-presenter/CHANGES +4 -0
- data/pakyow-presenter/lib/presenter/attributes.rb +31 -7
- data/pakyow-presenter/lib/presenter/base.rb +3 -0
- data/pakyow-presenter/lib/presenter/binder.rb +10 -6
- data/pakyow-presenter/lib/presenter/binder_set.rb +12 -5
- data/pakyow-presenter/lib/presenter/container.rb +6 -0
- data/pakyow-presenter/lib/presenter/doc_helpers.rb +7 -0
- data/pakyow-presenter/lib/presenter/exceptions.rb +4 -0
- data/pakyow-presenter/lib/presenter/helpers.rb +6 -4
- data/pakyow-presenter/lib/presenter/page.rb +44 -51
- data/pakyow-presenter/lib/presenter/partial.rb +1 -19
- data/pakyow-presenter/lib/presenter/presenter.rb +67 -51
- data/pakyow-presenter/lib/presenter/template.rb +11 -15
- data/pakyow-presenter/lib/presenter/title_helpers.rb +21 -0
- data/pakyow-presenter/lib/presenter/view.rb +280 -124
- data/pakyow-presenter/lib/presenter/view_collection.rb +108 -12
- data/pakyow-presenter/lib/presenter/view_composer.rb +194 -0
- data/pakyow-presenter/lib/presenter/view_store.rb +65 -18
- metadata +18 -15
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
module Pakyow
|
|
2
2
|
module Presenter
|
|
3
|
-
class Template
|
|
3
|
+
class Template < View
|
|
4
4
|
include DocHelpers
|
|
5
|
+
include TitleHelpers
|
|
6
|
+
|
|
5
7
|
attr_accessor :name, :doc
|
|
6
8
|
|
|
7
9
|
class << self
|
|
8
10
|
def load(path)
|
|
9
|
-
format =
|
|
11
|
+
format = Utils::String.split_at_last_dot(path)[-1]
|
|
10
12
|
contents = File.read(path)
|
|
11
13
|
name = File.basename(path, '.*').to_sym
|
|
12
14
|
|
|
@@ -14,17 +16,9 @@ module Pakyow
|
|
|
14
16
|
end
|
|
15
17
|
end
|
|
16
18
|
|
|
17
|
-
def initialize(name, contents, format = :html)
|
|
19
|
+
def initialize(name, contents = '', format = :html)
|
|
18
20
|
@name = name
|
|
19
|
-
|
|
20
|
-
if contents.is_a?(Nokogiri::HTML::Document)
|
|
21
|
-
@doc = contents
|
|
22
|
-
else
|
|
23
|
-
processed = Presenter.process(contents, format)
|
|
24
|
-
@doc = Nokogiri::HTML::Document.parse(processed)
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
containers
|
|
21
|
+
super(contents, format)
|
|
28
22
|
end
|
|
29
23
|
|
|
30
24
|
def initialize_copy(original_template)
|
|
@@ -32,6 +26,8 @@ module Pakyow
|
|
|
32
26
|
|
|
33
27
|
# copy doc
|
|
34
28
|
@doc = original_template.doc.dup
|
|
29
|
+
@context = original_template.context
|
|
30
|
+
@composer = original_template.composer
|
|
35
31
|
end
|
|
36
32
|
|
|
37
33
|
def container(name = :default)
|
|
@@ -48,9 +44,9 @@ module Pakyow
|
|
|
48
44
|
containers.each do |container|
|
|
49
45
|
name = container[0]
|
|
50
46
|
|
|
51
|
-
|
|
52
|
-
container(name).replace(content)
|
|
53
|
-
|
|
47
|
+
begin
|
|
48
|
+
container(name).replace(page.content(name))
|
|
49
|
+
rescue MissingContainer
|
|
54
50
|
Pakyow.logger.debug "No content for '#{name}' in page '#{page.path}'"
|
|
55
51
|
end
|
|
56
52
|
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module Pakyow
|
|
2
|
+
module Presenter
|
|
3
|
+
module TitleHelpers
|
|
4
|
+
def title=(title)
|
|
5
|
+
return if @doc.nil?
|
|
6
|
+
|
|
7
|
+
if o = @doc.css('title').first
|
|
8
|
+
o.inner_html = Nokogiri::HTML::fragment(title.to_s)
|
|
9
|
+
elsif o = @doc.css('head').first
|
|
10
|
+
o.add_child(Nokogiri::HTML::fragment("<title>#{title}</title>"))
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def title
|
|
15
|
+
return unless o = @doc.css('title').first
|
|
16
|
+
o.inner_text
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|