flurin-html_mockup 0.2.0 → 0.3.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.
- data/examples/config.ru +16 -0
- data/examples/script/server +12 -6
- data/lib/html_mockup/cli.rb +11 -20
- data/lib/html_mockup/server.rb +69 -0
- metadata +4 -2
data/examples/config.ru
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require 'pathname'
|
|
2
|
+
|
|
3
|
+
begin
|
|
4
|
+
require File.dirname(__FILE__) + "/../vendor/html_mockup/lib/html_mockup/server"
|
|
5
|
+
rescue LoadError => e
|
|
6
|
+
require 'rubygems'
|
|
7
|
+
require 'html_mockup/server'
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
root_path = Pathname.new(File.dirname(__FILE__)) + "html"
|
|
11
|
+
partial_path = (root_path + "../partials/").realpath
|
|
12
|
+
|
|
13
|
+
mockup = HtmlMockup::Server.new(root_path,partial_path)
|
|
14
|
+
|
|
15
|
+
run mockup.application
|
|
16
|
+
|
data/examples/script/server
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
|
|
3
|
+
require 'pathname'
|
|
4
|
+
|
|
3
5
|
begin
|
|
4
|
-
require File.dirname(__FILE__) + "/../vendor/html_mockup/lib/html_mockup/
|
|
6
|
+
require File.dirname(__FILE__) + "/../vendor/html_mockup/lib/html_mockup/server"
|
|
5
7
|
rescue LoadError => e
|
|
6
8
|
require 'rubygems'
|
|
7
|
-
require 'html_mockup/
|
|
9
|
+
require 'html_mockup/server'
|
|
8
10
|
end
|
|
9
11
|
|
|
12
|
+
root_path = Pathname.new(File.dirname(__FILE__)) + "../html"
|
|
13
|
+
partial_path = (root_path + "../partials/").realpath
|
|
14
|
+
|
|
15
|
+
mockup = HtmlMockup::Server.new(root_path,partial_path)
|
|
16
|
+
|
|
17
|
+
# Add some of your own middleware here.
|
|
18
|
+
# mockup.use Rack::CommonLogger
|
|
10
19
|
|
|
11
|
-
|
|
12
|
-
a.unshift(File.dirname(__FILE__) + "/../html")
|
|
13
|
-
a.unshift("serve")
|
|
14
|
-
HtmlMockup::Cli.start(a)
|
|
20
|
+
mockup.run
|
data/lib/html_mockup/cli.rb
CHANGED
|
@@ -15,29 +15,19 @@ module HtmlMockup
|
|
|
15
15
|
:partial_path => :optional, # Defaults to [directory]/../partials
|
|
16
16
|
:validate => :boolean # Automatically validate all HTML responses @ the w3c
|
|
17
17
|
def serve(path=".")
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
require File.dirname(__FILE__) + "/rack/html_validator"
|
|
22
|
-
chain = ::Rack::Builder.new do
|
|
23
|
-
use ::Rack::ShowExceptions
|
|
24
|
-
use ::Rack::Lint
|
|
25
|
-
end
|
|
26
|
-
chain.use Rack::HtmlValidator if options["validate"]
|
|
27
|
-
chain.run Rack::HtmlMockup.new(@path, @partial_path)
|
|
28
|
-
|
|
29
|
-
begin
|
|
30
|
-
server = ::Rack::Handler::Mongrel
|
|
31
|
-
rescue LoadError => e
|
|
32
|
-
server = ::Rack::Handler::WEBrick
|
|
33
|
-
end
|
|
18
|
+
require File.dirname(__FILE__) + '/server'
|
|
19
|
+
|
|
20
|
+
@path,@partial_path = template_paths(path,options["partial_path"])
|
|
34
21
|
|
|
35
22
|
server_options = {}
|
|
36
23
|
server_options[:Port] = options["port"] || "9000"
|
|
37
|
-
|
|
38
|
-
|
|
24
|
+
|
|
25
|
+
server = Server.new(@path,@partial_path,options,server_options)
|
|
26
|
+
|
|
27
|
+
puts "Running HtmlMockup with #{server.handler.inspect} on port #{server_options[:Port]}"
|
|
39
28
|
puts " Taking partials from #{@partial_path} (#{HtmlMockup::Template.partial_files(@partial_path).size} found)"
|
|
40
|
-
|
|
29
|
+
|
|
30
|
+
server.run
|
|
41
31
|
end
|
|
42
32
|
|
|
43
33
|
desc "validate [directory/file]", "Validates the file or all HTML in directory"
|
|
@@ -88,7 +78,8 @@ module HtmlMockup
|
|
|
88
78
|
|
|
89
79
|
mkdir(path + "script")
|
|
90
80
|
cp(example_path + "script/server",path + "script/server")
|
|
91
|
-
(path + "
|
|
81
|
+
cp(example_path + "config.ru",path + "config.ru")
|
|
82
|
+
(path + "script/server").chmod(0755)
|
|
92
83
|
end
|
|
93
84
|
end
|
|
94
85
|
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
require 'rack'
|
|
2
|
+
require File.dirname(__FILE__) + "/template"
|
|
3
|
+
require File.dirname(__FILE__) + "/w3c_validator"
|
|
4
|
+
require File.dirname(__FILE__) + "/rack/html_mockup"
|
|
5
|
+
require File.dirname(__FILE__) + "/rack/html_validator"
|
|
6
|
+
|
|
7
|
+
module HtmlMockup
|
|
8
|
+
class Server
|
|
9
|
+
attr_accessor :options,:server_options, :root, :partial_path
|
|
10
|
+
|
|
11
|
+
def initialize(root,partial_path,options={},server_options={})
|
|
12
|
+
@stack = ::Rack::Builder.new
|
|
13
|
+
|
|
14
|
+
@middleware = []
|
|
15
|
+
@root = root
|
|
16
|
+
@partial_path = partial_path
|
|
17
|
+
@options,@server_options = options,server_options
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Use the specified Rack middleware
|
|
21
|
+
def use(middleware, *args, &block)
|
|
22
|
+
@middleware << [middleware, args, block]
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def handler
|
|
26
|
+
@handler ||= detect_rack_handler
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def run
|
|
30
|
+
self.handler.run self.application, @server_options do |server|
|
|
31
|
+
trap(:INT) do
|
|
32
|
+
## Use thins' hard #stop! if available, otherwise just #stop
|
|
33
|
+
server.respond_to?(:stop!) ? server.stop! : server.stop
|
|
34
|
+
puts "Bby HtmlMockup"
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def application
|
|
40
|
+
return @app if @app
|
|
41
|
+
@stack.use ::Rack::ShowExceptions
|
|
42
|
+
@stack.use ::Rack::Lint
|
|
43
|
+
|
|
44
|
+
@middleware.each { |c,a,b| builder.use(c, *a, &b) }
|
|
45
|
+
|
|
46
|
+
@stack.use Rack::HtmlValidator if self.options["validate"]
|
|
47
|
+
@stack.run Rack::HtmlMockup.new(self.root, self.partial_path)
|
|
48
|
+
|
|
49
|
+
@app = @stack.to_app
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
protected
|
|
54
|
+
|
|
55
|
+
# Sinatra's detect_rack_handler
|
|
56
|
+
def detect_rack_handler
|
|
57
|
+
servers = %w[thin mongrel webrick]
|
|
58
|
+
servers.each do |server_name|
|
|
59
|
+
begin
|
|
60
|
+
return ::Rack::Handler.get(server_name.capitalize)
|
|
61
|
+
rescue LoadError
|
|
62
|
+
rescue NameError
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
raise "Server handler (#{servers.join(',')}) not found."
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
end
|
|
69
|
+
end
|
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.
|
|
4
|
+
version: 0.3.0
|
|
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
|
|
12
|
+
date: 2009-05-04 00:00:00 -07:00
|
|
13
13
|
default_executable: mockup
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
@@ -42,6 +42,7 @@ extra_rdoc_files:
|
|
|
42
42
|
- README.rdoc
|
|
43
43
|
files:
|
|
44
44
|
- bin/mockup
|
|
45
|
+
- examples/config.ru
|
|
45
46
|
- examples/html/green.gif
|
|
46
47
|
- examples/html/index.html
|
|
47
48
|
- examples/partials/test.part.rhtml
|
|
@@ -49,6 +50,7 @@ files:
|
|
|
49
50
|
- lib/html_mockup/cli.rb
|
|
50
51
|
- lib/html_mockup/rack/html_mockup.rb
|
|
51
52
|
- lib/html_mockup/rack/html_validator.rb
|
|
53
|
+
- lib/html_mockup/server.rb
|
|
52
54
|
- lib/html_mockup/template.rb
|
|
53
55
|
- lib/html_mockup/w3c_validator.rb
|
|
54
56
|
- README.rdoc
|