html_mockup 0.5.2 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +18 -17
- data/examples/default_template/CHANGELOG +0 -0
- data/examples/default_template/Gemfile +3 -0
- data/examples/default_template/Mockupfile +1 -0
- data/lib/html_mockup/cli.rb +20 -26
- data/lib/html_mockup/generators/new.rb +66 -0
- data/lib/html_mockup/generators.rb +6 -0
- data/lib/html_mockup/project.rb +6 -4
- data/lib/html_mockup/release/cleaner.rb +18 -0
- data/lib/html_mockup/release/finalizers/dir.rb +6 -2
- data/lib/html_mockup/release/finalizers/zip.rb +1 -0
- data/lib/html_mockup/release/injector.rb +4 -3
- data/lib/html_mockup/release/processors/requirejs.rb +58 -11
- data/lib/html_mockup/release.rb +64 -72
- data/lib/html_mockup/server.rb +10 -4
- metadata +12 -11
- data/examples/config.ru +0 -16
- data/examples/html/green.gif +0 -0
- data/examples/html/index.html +0 -18
- data/examples/partials/test.part.rhtml +0 -3
- data/examples/script/server +0 -20
data/README.rdoc
CHANGED
@@ -47,32 +47,33 @@ to access partials in subdirectories.
|
|
47
47
|
|
48
48
|
=== Mockup commandline
|
49
49
|
|
50
|
-
==== mockup
|
50
|
+
==== mockup serve [directory]
|
51
51
|
|
52
|
-
|
53
|
-
will be converted.
|
52
|
+
Serve can be used during development as a simple webserver (Puma, Mongrel, Thin, Webrick). It also supports on-the-fly HTML validation.
|
54
53
|
|
55
|
-
|
54
|
+
The directory to serve must contain `[directory]/html` and `[directory]/partials` (unless you have specified `--partial_path` and `--html_path`)
|
56
55
|
|
57
56
|
Options:
|
58
|
-
--
|
59
|
-
--
|
57
|
+
--port:: The port the server should listen on. Defaults to 9000
|
58
|
+
--partial_path:: the path where the partial files can be found (*.part.html), defaults to directory `[directory]/partials`
|
59
|
+
--html_path:: the path where the html files can be found (*.html), defaults to directory `[directory]/html`
|
60
|
+
--validate:: Flag to set wether or not we should validate all html files (defaults to false)
|
60
61
|
|
61
|
-
==== mockup
|
62
|
+
==== mockup release [directory]
|
62
63
|
|
63
|
-
|
64
|
-
on-the-fly HTML validation.
|
64
|
+
Makes a release of the current mockup project
|
65
65
|
|
66
|
-
|
66
|
+
==== mockup new [directory]
|
67
67
|
|
68
|
-
|
69
|
-
--port:: The port the server should listen on. Defaults to 9000
|
70
|
-
--partial_path:: the path where the partial files can be found (*.part.html), defaults to directory /../partials
|
71
|
-
--validate:: Flag to set wether or not we should validate all html files (defaults to false)
|
68
|
+
Generate creates a directory structure in directory for use with new HTML mockups.
|
72
69
|
|
73
|
-
==== mockup
|
70
|
+
==== mockup extract [source_path] [target_path]
|
74
71
|
|
75
|
-
|
72
|
+
Extract a fully relative html mockup into target_path. It will expand all absolute href's, src's and action's into relative links if they are absolute
|
73
|
+
|
74
|
+
Options:
|
75
|
+
--partial_path:: Defaults to [directory]/partials
|
76
|
+
--filter:: What files should be converted defaults to **/*.html
|
76
77
|
|
77
78
|
==== mockup validate [directory/file]
|
78
79
|
|
@@ -83,4 +84,4 @@ Options:
|
|
83
84
|
--filter:: What files should be validated, defaults to [^_]*.html
|
84
85
|
|
85
86
|
=== Copyright & license
|
86
|
-
Copyright (c)
|
87
|
+
Copyright (c) 2012 Flurin Egger, Edwin van der Graaf, DigitPaint, MIT Style License. (see MIT-LICENSE)
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
# Configure your mockup here
|
data/lib/html_mockup/cli.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'thor'
|
3
|
+
require 'thor/group'
|
3
4
|
|
4
5
|
require 'pathname'
|
5
6
|
require 'fileutils'
|
@@ -7,6 +8,7 @@ include FileUtils
|
|
7
8
|
|
8
9
|
require File.dirname(__FILE__) + "/template"
|
9
10
|
require File.dirname(__FILE__) + "/project"
|
11
|
+
require File.dirname(__FILE__) + "/generators"
|
10
12
|
require File.dirname(__FILE__) + "/w3c_validator"
|
11
13
|
|
12
14
|
module HtmlMockup
|
@@ -15,12 +17,22 @@ module HtmlMockup
|
|
15
17
|
method_options :port => :string, # Defaults to 9000
|
16
18
|
:html_path => :string, # The document root, defaults to "[directory]/html"
|
17
19
|
:partial_path => :string, # Defaults to [directory]/partials
|
18
|
-
:handler => :string # The handler to use (defaults to mongrel)
|
19
|
-
|
20
|
+
:handler => :string, # The handler to use (defaults to mongrel)
|
21
|
+
:validate => :boolean # Run validation?
|
22
|
+
def serve(path=".")
|
23
|
+
|
24
|
+
server_options = {}
|
25
|
+
options.each{|k,v| server_options[k.to_sym] = v }
|
26
|
+
server_options[:server] = {}
|
27
|
+
[:port, :handler, :validate].each do |k|
|
28
|
+
server_options[:server][k] = server_options.delete(k) if server_options.has_key?(k)
|
29
|
+
end
|
30
|
+
|
20
31
|
# Load the project, it should take care of all the paths
|
21
|
-
@project = initialize_project(path,
|
32
|
+
@project = initialize_project(path, server_options)
|
22
33
|
|
23
34
|
server = @project.server
|
35
|
+
server.set_options(server_options[:server])
|
24
36
|
|
25
37
|
puts "Running HtmlMockup with #{server.handler.inspect} on port #{server.port}"
|
26
38
|
puts banner(@project)
|
@@ -64,28 +76,10 @@ module HtmlMockup
|
|
64
76
|
end
|
65
77
|
end
|
66
78
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
puts "Directory #{path} already exists, please only use this to create new mockups"
|
72
|
-
else
|
73
|
-
example_path = Pathname.new(File.dirname(__FILE__) + "/../../examples")
|
74
|
-
path.mkpath
|
75
|
-
html_path = path + "html"
|
76
|
-
mkdir(html_path)
|
77
|
-
mkdir(html_path + "stylesheets")
|
78
|
-
mkdir(html_path + "images")
|
79
|
-
mkdir(html_path + "javascripts")
|
80
|
-
|
81
|
-
mkdir(path + "partials")
|
82
|
-
|
83
|
-
mkdir(path + "script")
|
84
|
-
cp(example_path + "script/server",path + "script/server")
|
85
|
-
cp(example_path + "config.ru",path + "config.ru")
|
86
|
-
(path + "script/server").chmod(0755)
|
87
|
-
end
|
88
|
-
end
|
79
|
+
register HtmlMockup::Generators::New, "new", "new [directory]", ""
|
80
|
+
# Hack to register our options/description
|
81
|
+
tasks["new"].options = HtmlMockup::Generators::New.class_options
|
82
|
+
tasks["new"].description = HtmlMockup::Generators::New.desc
|
89
83
|
|
90
84
|
desc "extract [source_path] [target_path]", "Extract a fully relative html mockup into target_path. It will expand all absolute href's, src's and action's into relative links if they are absolute"
|
91
85
|
method_options :partial_path => :string, # Defaults to [directory]/partials
|
@@ -113,7 +107,7 @@ module HtmlMockup
|
|
113
107
|
exit(1)
|
114
108
|
end
|
115
109
|
|
116
|
-
Project.new(path)
|
110
|
+
Project.new(path, options)
|
117
111
|
end
|
118
112
|
|
119
113
|
def w3cvalidate(file)
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'shellwords'
|
2
|
+
|
3
|
+
class HtmlMockup::Generators::New < Thor::Group
|
4
|
+
|
5
|
+
include Thor::Actions
|
6
|
+
|
7
|
+
desc "Create a new HTML mockup based on an existing skeleton"
|
8
|
+
argument :path, :type => :string, :required => true, :desc => "Path to generate mockup into"
|
9
|
+
class_option :template, :type => :string, :aliases => ["-t"], :desc => "Template to use, can be a path or a git repository remote, uses built in minimal as default"
|
10
|
+
|
11
|
+
attr_reader :source_paths
|
12
|
+
|
13
|
+
def setup_variables
|
14
|
+
self.destination_root = path
|
15
|
+
|
16
|
+
@source_paths = []
|
17
|
+
|
18
|
+
# Stuff to rm -rf later
|
19
|
+
@cleanup = []
|
20
|
+
end
|
21
|
+
|
22
|
+
def validate_path_is_empty
|
23
|
+
if File.directory?(self.destination_root)
|
24
|
+
say "Directory #{self.destination_root} already exists, please only use this to create new mockups"
|
25
|
+
exit(1)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def validate_template_path
|
30
|
+
if options[:template]
|
31
|
+
template = options[:template]
|
32
|
+
else
|
33
|
+
template = File.dirname(__FILE__) + "/../../../examples/default_template"
|
34
|
+
end
|
35
|
+
|
36
|
+
if File.exist?(template)
|
37
|
+
say "Taking template from #{template}"
|
38
|
+
@source_paths << template
|
39
|
+
else
|
40
|
+
# Hack to create temp directory
|
41
|
+
t = Tempfile.new("htmlmockup-generate-new")
|
42
|
+
tmp_dir = Pathname.new(t.path)
|
43
|
+
t.close
|
44
|
+
t.unlink
|
45
|
+
|
46
|
+
if run("git clone --depth=1 #{Shellwords.escape(template)} #{tmp_dir}")
|
47
|
+
say "Cloned template from #{template}"
|
48
|
+
run("rm -rf #{tmp_dir + ".git"}")
|
49
|
+
@source_paths << tmp_dir.to_s
|
50
|
+
@cleanup << tmp_dir.to_s
|
51
|
+
else
|
52
|
+
say "Template path #{template} doesn't seem to be a git remote or a local path"
|
53
|
+
exit(1)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
rescue Exception => e
|
57
|
+
puts e
|
58
|
+
puts e.backtrace.join("\n")
|
59
|
+
end
|
60
|
+
|
61
|
+
def create_mockup
|
62
|
+
directory(".", ".")
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
end
|
data/lib/html_mockup/project.rb
CHANGED
@@ -15,12 +15,12 @@ module HtmlMockup
|
|
15
15
|
def initialize(path, options={})
|
16
16
|
@path = Pathname.new(path)
|
17
17
|
|
18
|
-
options = {
|
18
|
+
@options = {
|
19
19
|
:html_path => @path + "html",
|
20
20
|
:partial_path => @path + "partials"
|
21
21
|
}.update(options)
|
22
22
|
|
23
|
-
paths = mockup_paths(options[:html_path], options[:partial_path])
|
23
|
+
paths = mockup_paths(@options[:html_path], @options[:partial_path])
|
24
24
|
self.html_path = paths[0]
|
25
25
|
self.partial_path = paths[1]
|
26
26
|
|
@@ -29,11 +29,13 @@ module HtmlMockup
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def server
|
32
|
-
@server
|
32
|
+
options = @options[:server] || {}
|
33
|
+
@server ||= Server.new(self, options)
|
33
34
|
end
|
34
35
|
|
35
36
|
def release
|
36
|
-
@release
|
37
|
+
options = @options[:release] || {}
|
38
|
+
@release ||= Release.new(self, options)
|
37
39
|
end
|
38
40
|
|
39
41
|
def html_path=(p)
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module HtmlMockup
|
2
|
+
class Release::Cleaner
|
3
|
+
def initialize(pattern)
|
4
|
+
@pattern = pattern
|
5
|
+
end
|
6
|
+
def call(release, options = {})
|
7
|
+
# We switch to the build path and append the globbed files for safety, so even if you manage to sneak in a
|
8
|
+
# pattern like "/**/*" it won't do you any good as it will be reappended to the path
|
9
|
+
Dir.chdir(release.build_path.to_s) do
|
10
|
+
Dir.glob(@pattern).each do |file|
|
11
|
+
path = File.join(release.build_path.to_s, file)
|
12
|
+
release.log(self, "Cleaning up \"#{path}\" in build")
|
13
|
+
rm(path)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -6,11 +6,15 @@ require 'fileutils'
|
|
6
6
|
#
|
7
7
|
module HtmlMockup::Release::Finalizers
|
8
8
|
class Dir < Base
|
9
|
+
def initialize(options = {})
|
10
|
+
@options = options
|
11
|
+
end
|
9
12
|
|
10
13
|
# @option options :prefix Prefix to put before the version (default = "html")
|
11
14
|
def call(release, options = {})
|
12
|
-
|
13
|
-
|
15
|
+
@options.update(options)
|
16
|
+
|
17
|
+
name = [(@options[:prefix] || "html"), release.scm.version].join("-")
|
14
18
|
release.log(self, "Finalizing release to #{release.target_path + name}")
|
15
19
|
|
16
20
|
if File.exist?(release.target_path + name)
|
@@ -37,11 +37,12 @@ module HtmlMockup
|
|
37
37
|
# @option options [Array] :into An array of file globs relative to the build_path
|
38
38
|
def initialize(variables, options)
|
39
39
|
@variables = variables
|
40
|
-
@
|
40
|
+
@options = options
|
41
41
|
end
|
42
42
|
|
43
|
-
def call(release)
|
44
|
-
|
43
|
+
def call(release, options = {})
|
44
|
+
@options.update(options)
|
45
|
+
files = release.get_files(@options[:into])
|
45
46
|
|
46
47
|
files.each do |f|
|
47
48
|
c = File.read(f)
|
@@ -1,28 +1,33 @@
|
|
1
1
|
require 'fileutils'
|
2
2
|
module HtmlMockup::Release::Processors
|
3
3
|
class Requirejs < Base
|
4
|
+
|
5
|
+
def initialize(options = {})
|
6
|
+
@options = {
|
7
|
+
:build_files => {"javascripts/site.build.js" => "javascripts"},
|
8
|
+
:rjs => "r.js",
|
9
|
+
:node => "node"
|
10
|
+
}.update(options)
|
11
|
+
end
|
12
|
+
|
4
13
|
|
5
14
|
# @option options [Hash] :build_files An a hash of files to build (as key) and the target directory in the release to put it as value, each one will be built in a separate directory. (default is {"javascripts/site.build.js" => "javascripts"})
|
6
15
|
# @option options [String] :node The system path for node (defaults to "node" in path)
|
7
16
|
# @option options [String] :rjs The system path to the requirejs optimizer (r.js) (defaults to "../vendor/requirejs/r.js" (relative to source_path))
|
8
17
|
def call(release, options={})
|
9
|
-
options
|
10
|
-
|
11
|
-
|
12
|
-
:node => "node"
|
13
|
-
}.update(options)
|
18
|
+
@options.update(options)
|
19
|
+
|
20
|
+
puts @options.inspect
|
14
21
|
|
15
22
|
begin
|
16
|
-
`#{options[:node]} -v`
|
23
|
+
`#{@options[:node]} -v`
|
17
24
|
rescue Errno::ENOENT
|
18
25
|
raise RuntimeError, "Could not find node in #{node.inspect}"
|
19
26
|
end
|
20
27
|
|
21
|
-
|
22
|
-
raise RuntimeError, "Could not find r.js optimizer at #{options[:rjs].inspect}"
|
23
|
-
end
|
28
|
+
rjs_command = rjs_check()
|
24
29
|
|
25
|
-
options[:build_files].each do |build_file, target|
|
30
|
+
@options[:build_files].each do |build_file, target|
|
26
31
|
build_file = release.build_path + build_file
|
27
32
|
target = release.build_path + target
|
28
33
|
release.log(self, "Optimizing #{build_file}")
|
@@ -34,7 +39,7 @@ module HtmlMockup::Release::Processors
|
|
34
39
|
t.unlink
|
35
40
|
|
36
41
|
# Run r.js optimizer
|
37
|
-
output = `#{
|
42
|
+
output = `#{rjs_command} -o #{build_file} dir=#{tmp_build_dir}`
|
38
43
|
|
39
44
|
# Check if r.js succeeded
|
40
45
|
unless $?.success?
|
@@ -50,5 +55,47 @@ module HtmlMockup::Release::Processors
|
|
50
55
|
FileUtils.mv(tmp_build_dir, target)
|
51
56
|
end
|
52
57
|
end
|
58
|
+
|
59
|
+
|
60
|
+
# Incase both a file and bin version are availble file version is taken
|
61
|
+
#
|
62
|
+
# @return rjs_command to invoke r.js optimizer with
|
63
|
+
|
64
|
+
def rjs_check(path = @options[:rjs])
|
65
|
+
rjs_command = rjs_file(path) || rjs_bin(path)
|
66
|
+
if !(rjs_command)
|
67
|
+
raise RuntimeError, "Could not find r.js optimizer in #{path.inspect} - try updating this by npm install -g requirejs"
|
68
|
+
end
|
69
|
+
rjs_command
|
70
|
+
end
|
71
|
+
|
72
|
+
protected
|
73
|
+
|
74
|
+
# Checks if the param is the r.js lib from file system
|
75
|
+
#
|
76
|
+
# @param [String] Path r.js lib may be kept to be invoked with node
|
77
|
+
# @return [String] the cli invokement string
|
78
|
+
def rjs_file(path)
|
79
|
+
if File.exist?(path)
|
80
|
+
"#{@options[:node]} #{path}"
|
81
|
+
else
|
82
|
+
false
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
# Checks if r.js is installed as bin
|
87
|
+
#
|
88
|
+
# @param [String] Path to r.js bin
|
89
|
+
# @return [String] the cli invokement string
|
90
|
+
def rjs_bin(path)
|
91
|
+
begin
|
92
|
+
`#{path} -v`
|
93
|
+
rescue Errno::ENOENT
|
94
|
+
false
|
95
|
+
else
|
96
|
+
"#{path}"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
53
100
|
end
|
54
101
|
end
|
data/lib/html_mockup/release.rb
CHANGED
@@ -7,14 +7,52 @@ module HtmlMockup
|
|
7
7
|
|
8
8
|
attr_reader :finalizers, :injections, :stack, :cleanups
|
9
9
|
|
10
|
-
|
11
|
-
[]
|
12
|
-
end
|
10
|
+
class << self
|
13
11
|
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
def default_stack
|
13
|
+
[]
|
14
|
+
end
|
15
|
+
|
16
|
+
def default_finalizers
|
17
|
+
[[self.get_callable(:dir, HtmlMockup::Release::Finalizers), {}]]
|
18
|
+
end
|
17
19
|
|
20
|
+
# Makes callable into a object that responds to call.
|
21
|
+
#
|
22
|
+
# @param [#call, Symbol, Class] callable If callable already responds to #call will just return callable, a Symbol will be searched for in the scope parameter, a class will be instantiated (and checked if it will respond to #call)
|
23
|
+
# @param [Module] scope The scope in which to search callable in if it's a Symbol
|
24
|
+
def get_callable(callable, scope)
|
25
|
+
return callable if callable.respond_to?(:call)
|
26
|
+
|
27
|
+
if callable.kind_of?(Symbol)
|
28
|
+
callable = camel_case(callable.to_s).to_sym
|
29
|
+
if scope.constants.include?(callable)
|
30
|
+
c = scope.const_get(callable)
|
31
|
+
callable = c if c.is_a?(Class)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
if callable.kind_of?(Class)
|
36
|
+
callable = callable.new
|
37
|
+
end
|
38
|
+
|
39
|
+
if callable.respond_to?(:call)
|
40
|
+
callable
|
41
|
+
else
|
42
|
+
raise ArgumentError, "Could not resolve #{callable.inspect}. Callable must be an object that responds to #call or a symbol that resolve to such an object or a class with a #call instance method."
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
# Nothing genius adjusted from:
|
48
|
+
# http://stackoverflow.com/questions/9524457/converting-string-from-snake-case-to-camel-case-in-ruby
|
49
|
+
def camel_case(string)
|
50
|
+
return string if string !~ /_/ && string =~ /[A-Z]+.*/
|
51
|
+
string.split('_').map{|e| e.capitalize}.join
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
18
56
|
# @option config [Symbol] :scm The SCM to use (default = :git)
|
19
57
|
# @option config [String, Pathname] :target_path The path/directory to put the release into
|
20
58
|
# @option config [String, Pathname]:build_path Temporary path used to build the release
|
@@ -30,10 +68,8 @@ module HtmlMockup
|
|
30
68
|
|
31
69
|
@config = {}.update(defaults).update(config)
|
32
70
|
@project = project
|
33
|
-
@finalizers = []
|
34
|
-
@injections = []
|
35
71
|
@stack = []
|
36
|
-
@
|
72
|
+
@finalizers = []
|
37
73
|
end
|
38
74
|
|
39
75
|
# Accessor for target_path
|
@@ -78,7 +114,7 @@ module HtmlMockup
|
|
78
114
|
# release.inject({"VERSION" => release.version, "DATE" => release.date}, :into => %w{_doc/toc.html})
|
79
115
|
# release.inject({"CHANGELOG" => {:file => "", :filter => BlueCloth}}, :into => %w{_doc/changelog.html})
|
80
116
|
def inject(variables, options)
|
81
|
-
@
|
117
|
+
@stack << Injector.new(variables, options)
|
82
118
|
end
|
83
119
|
|
84
120
|
# Use a certain pre-processor
|
@@ -86,7 +122,7 @@ module HtmlMockup
|
|
86
122
|
# @examples
|
87
123
|
# release.use :sprockets, sprockets_config
|
88
124
|
def use(processor, options = {})
|
89
|
-
@stack << [processor, options]
|
125
|
+
@stack << [self.class.get_callable(processor, HtmlMockup::Release::Processors), options]
|
90
126
|
end
|
91
127
|
|
92
128
|
# Write out the whole release into a directory, zip file or anything you can imagine
|
@@ -99,7 +135,7 @@ module HtmlMockup
|
|
99
135
|
# @examples
|
100
136
|
# release.finalize :zip
|
101
137
|
def finalize(finalizer, options = {})
|
102
|
-
@
|
138
|
+
@finalize << [self.class.get_callable(finalizer, HtmlMockup::Release::Finalizers), options]
|
103
139
|
end
|
104
140
|
|
105
141
|
# Files to clean up in the build directory just before finalization happens
|
@@ -109,7 +145,7 @@ module HtmlMockup
|
|
109
145
|
# @examples
|
110
146
|
# release.cleanup "**/.DS_Store"
|
111
147
|
def cleanup(pattern)
|
112
|
-
@
|
148
|
+
@stack << Cleaner.new(pattern)
|
113
149
|
end
|
114
150
|
|
115
151
|
# Generates a banner if a block is given, or returns the currently set banner.
|
@@ -161,12 +197,6 @@ module HtmlMockup
|
|
161
197
|
|
162
198
|
# Run stack
|
163
199
|
run_stack!
|
164
|
-
|
165
|
-
# Run injections
|
166
|
-
run_injections!
|
167
|
-
|
168
|
-
# Run cleanups
|
169
|
-
run_cleanups!
|
170
200
|
|
171
201
|
# Run finalizers
|
172
202
|
run_finalizers!
|
@@ -212,36 +242,25 @@ module HtmlMockup
|
|
212
242
|
|
213
243
|
def run_stack!
|
214
244
|
@stack = self.class.default_stack.dup if @stack.empty?
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
245
|
+
|
246
|
+
# call all objects in @stack
|
247
|
+
@stack.each do |task|
|
248
|
+
if (task.kind_of?(Array))
|
249
|
+
task[0].call(self, task[1])
|
250
|
+
else
|
251
|
+
task.call(self)
|
252
|
+
end
|
223
253
|
end
|
224
254
|
end
|
225
|
-
|
255
|
+
|
226
256
|
def run_finalizers!
|
227
257
|
@finalizers = self.class.default_finalizers.dup if @finalizers.empty?
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
def run_cleanups!
|
234
|
-
# We switch to the build path and append the globbed files for safety, so even if you manage to sneak in a
|
235
|
-
# pattern like "/**/*" it won't do you any good as it will be reappended to the path
|
236
|
-
Dir.chdir(self.build_path.to_s) do
|
237
|
-
@cleanups.each do |pattern|
|
238
|
-
Dir.glob(pattern).each do |file|
|
239
|
-
path = File.join(self.build_path.to_s, file)
|
240
|
-
log(self, "Cleaning up \"#{path}\" in build")
|
241
|
-
rm(path)
|
242
|
-
end
|
243
|
-
end
|
258
|
+
|
259
|
+
# call all objects in @finalizes
|
260
|
+
@finalizers.each do |finalizer|
|
261
|
+
finalizer[0].call(self, finalizer[1])
|
244
262
|
end
|
263
|
+
|
245
264
|
end
|
246
265
|
|
247
266
|
def cleanup!
|
@@ -249,34 +268,6 @@ module HtmlMockup
|
|
249
268
|
rm_rf(self.build_path)
|
250
269
|
end
|
251
270
|
|
252
|
-
# Makes callable into a object that responds to call.
|
253
|
-
#
|
254
|
-
# @param [#call, Symbol, Class] callable If callable already responds to #call will just return callable, a Symbol will be searched for in the scope parameter, a class will be instantiated (and checked if it will respond to #call)
|
255
|
-
# @param [Module] scope The scope in which to search callable in if it's a Symbol
|
256
|
-
def get_callable(callable, scope)
|
257
|
-
return callable if callable.respond_to?(:call)
|
258
|
-
|
259
|
-
if callable.kind_of?(Symbol)
|
260
|
-
# TODO camelcase callable
|
261
|
-
callable = callable.to_s.capitalize.to_sym
|
262
|
-
if scope.constants.include?(callable)
|
263
|
-
c = scope.const_get(callable)
|
264
|
-
callable = c if c.is_a?(Class)
|
265
|
-
end
|
266
|
-
end
|
267
|
-
|
268
|
-
if callable.kind_of?(Class)
|
269
|
-
callable = callable.new
|
270
|
-
end
|
271
|
-
|
272
|
-
if callable.respond_to?(:call)
|
273
|
-
callable
|
274
|
-
else
|
275
|
-
raise ArgumentError, "Could not resolve #{callable.inspect}. Callable must be an object that responds to #call or a symbol that resolve to such an object or a class with a #call instance method."
|
276
|
-
end
|
277
|
-
|
278
|
-
end
|
279
|
-
|
280
271
|
# @param [String] string The string to comment
|
281
272
|
#
|
282
273
|
# @option options [:html, :css, :js] :style The comment style to use (default=:js, which is the same as :css)
|
@@ -308,5 +299,6 @@ end
|
|
308
299
|
require File.dirname(__FILE__) + "/extractor"
|
309
300
|
require File.dirname(__FILE__) + "/release/scm"
|
310
301
|
require File.dirname(__FILE__) + "/release/injector"
|
302
|
+
require File.dirname(__FILE__) + "/release/cleaner"
|
311
303
|
require File.dirname(__FILE__) + "/release/finalizers"
|
312
304
|
require File.dirname(__FILE__) + "/release/processors"
|
data/lib/html_mockup/server.rb
CHANGED
@@ -17,14 +17,20 @@ module HtmlMockup
|
|
17
17
|
@stack = initialize_rack_builder
|
18
18
|
|
19
19
|
@project = project
|
20
|
-
|
20
|
+
|
21
|
+
set_options(options)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Sets the options, this is a separate method as we want to override certain
|
25
|
+
# things set in the mockupfile from the commandline
|
26
|
+
def set_options(options)
|
21
27
|
@options = {
|
22
28
|
:handler => nil, # Autodetect
|
23
29
|
:port => 9000
|
24
30
|
}.update(options)
|
25
31
|
|
26
|
-
|
27
|
-
|
32
|
+
self.port = @options[:port]
|
33
|
+
self.handler = @options[:handler]
|
28
34
|
end
|
29
35
|
|
30
36
|
# Use the specified Rack middleware
|
@@ -58,7 +64,7 @@ module HtmlMockup
|
|
58
64
|
def application
|
59
65
|
return @app if @app
|
60
66
|
|
61
|
-
@stack.use Rack::HtmlValidator if self.options[
|
67
|
+
@stack.use Rack::HtmlValidator if self.options[:validate]
|
62
68
|
@stack.run Rack::HtmlMockup.new(self.project.html_path, self.project.partial_path)
|
63
69
|
|
64
70
|
@app = @stack
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: html_mockup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-11-13 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: thor
|
17
|
-
requirement: &
|
17
|
+
requirement: &70177258865640 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ~>
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: 0.16.0
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70177258865640
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: rack
|
28
|
-
requirement: &
|
28
|
+
requirement: &70177258864880 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,7 +33,7 @@ dependencies:
|
|
33
33
|
version: 1.0.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70177258864880
|
37
37
|
description:
|
38
38
|
email: flurin@digitpaint.nl
|
39
39
|
executables:
|
@@ -43,19 +43,20 @@ extra_rdoc_files:
|
|
43
43
|
- README.rdoc
|
44
44
|
files:
|
45
45
|
- bin/mockup
|
46
|
-
- examples/
|
47
|
-
- examples/
|
48
|
-
- examples/
|
49
|
-
- examples/partials/test.part.rhtml
|
50
|
-
- examples/script/server
|
46
|
+
- examples/default_template/CHANGELOG
|
47
|
+
- examples/default_template/Gemfile
|
48
|
+
- examples/default_template/Mockupfile
|
51
49
|
- lib/html_mockup/cli.rb
|
52
50
|
- lib/html_mockup/extractor.rb
|
51
|
+
- lib/html_mockup/generators.rb
|
52
|
+
- lib/html_mockup/generators/new.rb
|
53
53
|
- lib/html_mockup/mockupfile.rb
|
54
54
|
- lib/html_mockup/project.rb
|
55
55
|
- lib/html_mockup/rack/html_mockup.rb
|
56
56
|
- lib/html_mockup/rack/html_validator.rb
|
57
57
|
- lib/html_mockup/rack/sleep.rb
|
58
58
|
- lib/html_mockup/release.rb
|
59
|
+
- lib/html_mockup/release/cleaner.rb
|
59
60
|
- lib/html_mockup/release/finalizers.rb
|
60
61
|
- lib/html_mockup/release/finalizers/dir.rb
|
61
62
|
- lib/html_mockup/release/finalizers/zip.rb
|
data/examples/config.ru
DELETED
@@ -1,16 +0,0 @@
|
|
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/html/green.gif
DELETED
Binary file
|
data/examples/html/index.html
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
2
|
-
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
3
|
-
|
4
|
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
5
|
-
<head>
|
6
|
-
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
7
|
-
|
8
|
-
<title>untitled</title>
|
9
|
-
|
10
|
-
</head>
|
11
|
-
|
12
|
-
<body>
|
13
|
-
<!-- [START:test?id=bla] -->
|
14
|
-
<!-- [STOP:test] -->
|
15
|
-
|
16
|
-
<img src="green.gif" alt="Green" />
|
17
|
-
</body>
|
18
|
-
</html>
|
data/examples/script/server
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'pathname'
|
4
|
-
|
5
|
-
begin
|
6
|
-
require File.dirname(__FILE__) + "/../vendor/html_mockup/lib/html_mockup/server"
|
7
|
-
rescue LoadError => e
|
8
|
-
require 'rubygems'
|
9
|
-
require 'html_mockup/server'
|
10
|
-
end
|
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
|
19
|
-
|
20
|
-
mockup.run
|