templette 0.5.1 → 0.5.2

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.
@@ -19,14 +19,22 @@ module Templette
19
19
  end
20
20
 
21
21
  def partial(filename) # :nodoc:
22
- raise PageError.new(page, "Rendering #{filename} failed. File not found.") unless File.exists?(filename)
23
- Engineer.engine_for(Engineer.determine_type(filename)).render(File.read(filename), page._binding)
22
+ raise PageError.new(page, "Rendering #{partial_path(filename)} failed. File not found.") unless File.exists?(partial_path(filename))
23
+ Engineer.engine_for(Engineer.determine_type(filename)).render(File.read(partial_path(filename)), page._binding)
24
24
  rescue RenderError => e
25
25
  raise PageError.new(page, e.message)
26
26
  end
27
27
 
28
28
  private
29
29
 
30
+ def partial_path(filename)
31
+ if filename =~ Regexp.new(Page::pages_dir)
32
+ filename
33
+ else
34
+ Page::pages_dir + filename
35
+ end
36
+ end
37
+
30
38
  def generate_accessor(k, v)
31
39
  raise TempletteError.new(page, "Method already defined: #{k}. Change your config file and stop using it!") if self.methods.include?(k.to_s)
32
40
  if v.kind_of?(Hash)
@@ -5,9 +5,21 @@ module Templette
5
5
  class Haml
6
6
 
7
7
  def render(html, the_binding)
8
- ::Haml::Engine.new(html).render(the_binding)
8
+ with_no_warnings { ::Haml::Engine.new(html).render(the_binding) }
9
9
  end
10
-
10
+
11
+
12
+ def with_no_warnings
13
+ save = $-w
14
+ $-w = false
15
+
16
+ begin
17
+ yield
18
+ ensure
19
+ $-w = save
20
+ end
21
+ end
22
+
11
23
  end
12
24
  end
13
25
  end
@@ -24,9 +24,11 @@ module Templette
24
24
  include Templette::DataAccessors
25
25
  attr_reader :name, :template
26
26
 
27
+ PAGES_DEFAULT = 'pages/'
28
+
27
29
  class <<self
28
30
  def pages_dir
29
- @@pages_dir ||= 'pages'
31
+ @@pages_dir ||= PAGES_DEFAULT
30
32
  end
31
33
 
32
34
  def pages_dir=(path)
@@ -36,7 +38,7 @@ module Templette
36
38
  # Grabs all of the yaml files found in /pages, and loads them as
37
39
  # Page objects.
38
40
  def find_all
39
- Dir["#{pages_dir}/**/*.yml"].map {|f| new f }
41
+ Dir["#{pages_dir}**/*.yml"].map {|f| new f }
40
42
  end
41
43
  end
42
44
 
@@ -45,7 +47,7 @@ module Templette
45
47
 
46
48
  data = YAML::load_file(page_config)
47
49
  @name = page_config.dup
48
- @name.slice!(self.class.pages_dir + '/')
50
+ @name.slice!(self.class.pages_dir)
49
51
  @name.chomp!('.yml')
50
52
  raise PageError.new(self, "missing required section \"template_name\" for page config #{page_config}") unless data['template_name']
51
53
  @template = Template.new(data['template_name'])
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: templette
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jacob Dunphy and Steve Holder
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-02-27 00:00:00 -08:00
12
+ date: 2009-03-05 00:00:00 -08:00
13
13
  default_executable: templette
14
14
  dependencies: []
15
15