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.
@@ -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 = StringUtils.split_at_last_dot(path)[-1]
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
- if content = page.content(name)
52
- container(name).replace(content)
53
- else
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
+