html_mockup 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.
@@ -20,13 +20,16 @@ module HtmlMockup
20
20
  :partial_path => @path + "partials"
21
21
  }.update(options)
22
22
 
23
- html_path, partial_path = mockup_paths(options[:html_path], options[:partial_path])
23
+ paths = mockup_paths(options[:html_path], options[:partial_path])
24
+ self.html_path = paths[0]
25
+ self.partial_path = paths[1]
26
+
24
27
  @mockupfile = Mockupfile.new(self)
25
28
  @mockupfile.load
26
29
  end
27
30
 
28
31
  def server
29
- @server ||= Server.new(self.html_path, self.partial_path)
32
+ @server ||= Server.new(self)
30
33
  end
31
34
 
32
35
  def release
@@ -26,8 +26,8 @@ module HtmlMockup::Release::Processors
26
26
 
27
27
  # Add version numbers and minify the files
28
28
  release.get_files(options[:match], options[:skip]).each do |f|
29
- type = f[/\.(.+)$/,1]
30
-
29
+ type = f[/\.([^.]+)\Z/,1]
30
+
31
31
  data = File.read(f);
32
32
  File.open(f,"w") do |fh|
33
33
 
@@ -42,8 +42,11 @@ module HtmlMockup::Release::Processors
42
42
  minified << css_compressor.compress(data)
43
43
  when "js"
44
44
  minified << js_compressor.compress(data)
45
+ else
46
+ release.log self, "Error minifying: encountered unknown type \"#{type}\""
47
+ minified << data
45
48
  end
46
-
49
+
47
50
  fh.write minified.join("\n")
48
51
  end
49
52
  end
@@ -9,16 +9,15 @@ module HtmlMockup
9
9
 
10
10
  attr_reader :options
11
11
 
12
- attr_accessor :html_path, :partial_path
13
-
12
+ attr_reader :project
13
+
14
14
  attr_accessor :port, :handler
15
15
 
16
- def initialize(html_path, partial_path, options={})
17
- @stack = ::Rack::Builder.new
16
+ def initialize(project, options={})
17
+ @stack = initialize_rack_builder
18
+
19
+ @project = project
18
20
 
19
- @middleware = []
20
- @html_path = html_path
21
- @partial_path = partial_path
22
21
  @options = {
23
22
  :handler => nil, # Autodetect
24
23
  :port => 9000
@@ -29,26 +28,21 @@ module HtmlMockup
29
28
  end
30
29
 
31
30
  # Use the specified Rack middleware
32
- def use(middleware, *args, &block)
33
- @middleware << [middleware, args, block]
31
+ #
32
+ # @see ::Rack::Builder#use
33
+ def use(*args, &block)
34
+ @stack.use *args, &block
34
35
  end
35
36
 
36
- def handler
37
- if self.options[:handler]
38
- begin
39
- @handler = ::Rack::Handler.get(self.handler)
40
- rescue LoadError
41
- rescue NameError
42
- end
43
- if @handler.nil?
44
- puts "Handler '#{self.options[:handler]}' not found, using fallback."
45
- end
46
- end
47
- @handler ||= detect_rack_handler
37
+ # Use the map handler to map endpoints to certain urls
38
+ #
39
+ # @see ::Rack::Builder#map
40
+ def map(*args, &block)
41
+ @stack.map *args, &block
48
42
  end
49
-
43
+
50
44
  def run!
51
- self.handler.run self.application, self.server_options do |server|
45
+ self.get_handler(self.handler).run self.application, self.server_options do |server|
52
46
  trap(:INT) do
53
47
  ## Use thins' hard #stop! if available, otherwise just #stop
54
48
  server.respond_to?(:stop!) ? server.stop! : server.stop
@@ -57,45 +51,60 @@ module HtmlMockup
57
51
  end
58
52
  end
59
53
  alias :run :run!
54
+
55
+ protected
60
56
 
57
+ # Build the final application that get's run by the Rack Handler
61
58
  def application
62
59
  return @app if @app
63
- @stack.use ::Rack::ShowExceptions
64
- @stack.use ::Rack::Lint
65
- @stack.use ::Rack::ConditionalGet
66
- @stack.use ::Rack::Head
67
-
68
- @middleware.each { |c,a,b| @stack.use(c, *a, &b) }
69
60
 
70
61
  @stack.use Rack::HtmlValidator if self.options["validate"]
71
- @stack.run Rack::HtmlMockup.new(self.html_path, self.partial_path)
62
+ @stack.run Rack::HtmlMockup.new(self.project.html_path, self.project.partial_path)
72
63
 
73
- @app = @stack.to_app
74
- end
75
-
76
-
77
- protected
64
+ @app = @stack
65
+ end
78
66
 
79
- # Generate server options for handler
80
- def server_options
81
- {
82
- :Port => self.port
83
- }
67
+ # Initialize the Rack builder instance for this server
68
+ #
69
+ # @return ::Rack::Builder instance
70
+ def initialize_rack_builder
71
+ builder = ::Rack::Builder.new
72
+ builder.use ::Rack::ShowExceptions
73
+ builder.use ::Rack::Lint
74
+ builder.use ::Rack::ConditionalGet
75
+ builder.use ::Rack::Head
76
+
77
+ builder
84
78
  end
85
79
 
86
-
87
- # Sinatra's detect_rack_handler
88
- def detect_rack_handler
89
- servers = %w[mongrel thin webrick]
90
- servers.each do |server_name|
80
+ # Get the actual handler for use in the server
81
+ # Will always return a handler, it will try to use the fallbacks
82
+ def get_handler(preferred_handler_name = nil)
83
+ servers = %w[puma mongrel thin webrick]
84
+ servers.unshift(preferred_handler_name) if preferred_handler_name
85
+
86
+ handler = nil
87
+ while((server_name = servers.shift) && handler === nil) do
91
88
  begin
92
- return ::Rack::Handler.get(server_name)
89
+ handler = ::Rack::Handler.get(server_name)
93
90
  rescue LoadError
94
91
  rescue NameError
95
92
  end
96
93
  end
97
- raise "Server handler (#{servers.join(',')}) not found."
98
- end
94
+
95
+ if preferred_handler_name && server_name != preferred_handler_name
96
+ puts "Handler '#{preferred_handler_name}' not found, using fallback ('#{server_name}')."
97
+ end
98
+ handler
99
+ end
99
100
 
101
+
102
+ # Generate server options for handler
103
+ def server_options
104
+ {
105
+ :Port => self.port
106
+ }
107
+ end
108
+
100
109
  end
101
110
  end
metadata CHANGED
@@ -1,19 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: html_mockup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Flurin Egger
9
+ - Edwin van der Graaf
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2012-10-10 00:00:00.000000000 Z
13
+ date: 2012-10-31 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: thor
16
- requirement: &70226277925520 !ruby/object:Gem::Requirement
17
+ requirement: &70150939878780 !ruby/object:Gem::Requirement
17
18
  none: false
18
19
  requirements:
19
20
  - - ~>
@@ -21,10 +22,10 @@ dependencies:
21
22
  version: 0.16.0
22
23
  type: :runtime
23
24
  prerelease: false
24
- version_requirements: *70226277925520
25
+ version_requirements: *70150939878780
25
26
  - !ruby/object:Gem::Dependency
26
27
  name: rack
27
- requirement: &70226277924900 !ruby/object:Gem::Requirement
28
+ requirement: &70150939877560 !ruby/object:Gem::Requirement
28
29
  none: false
29
30
  requirements:
30
31
  - - ! '>='
@@ -32,7 +33,7 @@ dependencies:
32
33
  version: 1.0.0
33
34
  type: :runtime
34
35
  prerelease: false
35
- version_requirements: *70226277924900
36
+ version_requirements: *70150939877560
36
37
  description:
37
38
  email: flurin@digitpaint.nl
38
39
  executables:
@@ -55,7 +56,6 @@ files:
55
56
  - lib/html_mockup/rack/html_validator.rb
56
57
  - lib/html_mockup/rack/sleep.rb
57
58
  - lib/html_mockup/release.rb
58
- - lib/html_mockup/release/extractor.rb
59
59
  - lib/html_mockup/release/finalizers.rb
60
60
  - lib/html_mockup/release/finalizers/dir.rb
61
61
  - lib/html_mockup/release/finalizers/zip.rb
@@ -70,7 +70,7 @@ files:
70
70
  - lib/html_mockup/template.rb
71
71
  - lib/html_mockup/w3c_validator.rb
72
72
  - README.rdoc
73
- homepage: http://github.com/flurin/html_mockup
73
+ homepage: http://github.com/digitpaint/html_mockup
74
74
  licenses: []
75
75
  post_install_message:
76
76
  rdoc_options:
@@ -1,25 +0,0 @@
1
- # Extracts the actual mockup into a directory and makes URLs
2
- # relative.
3
- class Release::Extractor
4
-
5
-
6
- # Resolves an url to a true file on disk:
7
- #
8
- # * it will add index.html if it's a directory
9
- # * it will try to append .html or .htm if it's not a directory
10
- def resolve_path(path)
11
- path = Pathname.new(path) unless path.kind_of?(Pathname)
12
- # Append index.html/index.htm/index.rhtml if it's a diretory
13
- if path.directory?
14
- search_files = %w{.html .htm}.map!{|p| path + "index#{p}" }
15
- # If it ends with a slash or does not contain a . and it's not a directory
16
- # try to add .html/.htm/.rhtml to see if that exists.
17
- elsif (path.to_s =~ /\/$/) || (path.to_s =~ /^[^.]+$/)
18
- search_files = [path.to_s + ".html", path.to_s + ".htm"].map!{|p| Pathname.new(p) }
19
- else
20
- search_files = [path]
21
- end
22
- search_files.find{|p| p.exist? }
23
- end
24
-
25
- end