flurin-html_mockup 0.1.1 → 0.1.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.
@@ -36,6 +36,7 @@ module HtmlMockup
36
36
  server_options[:Port] = options["port"] || "9000"
37
37
 
38
38
  puts "Running #{server.inspect} on port #{server_options[:Port]}"
39
+ puts " Taking partials from #{@partial_path} (#{HtmlMockup::Template.partial_files(@partial_path).size} found)"
39
40
  server.run chain.to_app, server_options
40
41
  end
41
42
 
@@ -116,7 +117,7 @@ module HtmlMockup
116
117
 
117
118
  def template_paths(path,partial_path=nil)
118
119
  path = Pathname.new(path)
119
- partial_path = partial_path && Pathname.new(partial_path) || (path + "../partials/").cleanpath
120
+ partial_path = partial_path && Pathname.new(partial_path) || (path + "../partials/").realpath
120
121
  [path,partial_path]
121
122
  end
122
123
 
@@ -31,12 +31,21 @@ module HtmlMockup
31
31
 
32
32
  if template_path = search_files.find{|p| File.exist?(p)}
33
33
  env["rack.errors"].puts "Rendering template #{template_path.inspect} (#{path.inspect})"
34
- templ = ::HtmlMockup::Template.open(template_path, :partial_path => @partial_path)
35
- resp = ::Rack::Response.new do |res|
36
- res.status = 200
37
- res.write templ.render
34
+ begin
35
+ templ = ::HtmlMockup::Template.open(template_path, :partial_path => @partial_path)
36
+ resp = ::Rack::Response.new do |res|
37
+ res.status = 200
38
+ res.write templ.render
39
+ end
40
+ resp.finish
41
+ rescue StandardError => e
42
+ env["rack.errors"].puts " #{e.message}"
43
+ resp = ::Rack::Response.new do |res|
44
+ res.status = 500
45
+ res.write "An error occurred"
46
+ end
47
+ resp.finish
38
48
  end
39
- resp.finish
40
49
  else
41
50
  env["rack.errors"].puts "Invoking file handler for #{path.inspect}"
42
51
  @file_server.call(env)
@@ -4,6 +4,9 @@ require 'erb'
4
4
  require 'cgi'
5
5
 
6
6
  module HtmlMockup
7
+
8
+ class MissingPartial < StandardError; end
9
+
7
10
  class Template
8
11
 
9
12
  class << self
@@ -24,7 +27,7 @@ module HtmlMockup
24
27
  end
25
28
 
26
29
  def partial_files(path)
27
- filter = "*.part.?html"
30
+ filter = "*.part.{?h,h}tml"
28
31
  files = []
29
32
  Dir.chdir(Pathname.new(path)) do
30
33
  files = Dir.glob(filter)
@@ -104,8 +107,10 @@ module HtmlMockup
104
107
  [tag,params,scanned]
105
108
  end
106
109
 
107
- def render_partial(tag,params)
108
- return nil unless self.available_partials[tag]
110
+ def render_partial(tag,params)
111
+ unless self.available_partials[tag]
112
+ raise MissingPartial.new("Could not find partial '#{tag}' in partial path '#{@options[:partial_path]}'")
113
+ end
109
114
  template = ERB.new(self.available_partials[tag])
110
115
  context = TemplateContext.new(params)
111
116
  "\n" + template.result(context.get_binding).rstrip + "\n<!-- [STOP:#{tag}] -->"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flurin-html_mockup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Flurin Egger
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-14 00:00:00 -07:00
12
+ date: 2009-04-20 00:00:00 -07:00
13
13
  default_executable: mockup
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency