html_mockup 0.8.4 → 0.9.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.
Files changed (50) hide show
  1. data/.gitignore +2 -2
  2. data/.travis.yml +12 -0
  3. data/CHANGELOG.md +11 -0
  4. data/Gemfile +5 -0
  5. data/README.md +95 -0
  6. data/Rakefile +9 -4
  7. data/bin/mockup +1 -1
  8. data/doc/cli.md +46 -0
  9. data/doc/mockupfile.md +3 -0
  10. data/doc/templating.md +88 -0
  11. data/html_mockup.gemspec +8 -4
  12. data/lib/html_mockup/cli.rb +57 -65
  13. data/lib/html_mockup/cli/command.rb +23 -0
  14. data/lib/html_mockup/cli/generate.rb +5 -0
  15. data/lib/html_mockup/cli/release.rb +10 -0
  16. data/lib/html_mockup/cli/serve.rb +29 -0
  17. data/lib/html_mockup/generators.rb +18 -1
  18. data/lib/html_mockup/generators/generator.rb +23 -0
  19. data/lib/html_mockup/generators/new.rb +4 -3
  20. data/lib/html_mockup/generators/templates/generator.tt +13 -0
  21. data/lib/html_mockup/project.rb +11 -11
  22. data/lib/html_mockup/release.rb +3 -3
  23. data/lib/html_mockup/resolver.rb +51 -28
  24. data/lib/html_mockup/template.rb +95 -11
  25. data/roger.gemspec +29 -0
  26. data/test/project/Gemfile +2 -1
  27. data/test/project/Gemfile.lock +17 -12
  28. data/test/project/Mockupfile +3 -0
  29. data/test/project/html/formats/index.html +1 -0
  30. data/test/project/html/formats/json.json.erb +0 -0
  31. data/test/project/html/layouts/content-for.html.erb +17 -0
  32. data/test/project/html/mockup/encoding.html +3 -0
  33. data/test/project/html/partials/load_path.html.erb +3 -0
  34. data/test/project/layouts/test.html.erb +8 -1
  35. data/test/project/layouts/yield.html.erb +1 -0
  36. data/test/project/lib/generators/test.rb +9 -0
  37. data/test/project/partials/formats/erb.html.erb +1 -0
  38. data/test/project/partials/partials-test.html.erb +1 -0
  39. data/test/project/partials/test/front_matter.html.erb +1 -0
  40. data/test/project/partials/test/json.json.erb +1 -0
  41. data/test/project/partials/test/simple.html.erb +1 -0
  42. data/test/project/partials2/partials2-test.html.erb +1 -0
  43. data/test/unit/cli_test.rb +12 -0
  44. data/test/unit/generators_test.rb +75 -0
  45. data/test/unit/release/cleaner_test.rb +13 -8
  46. data/test/unit/resolver_test.rb +92 -0
  47. data/test/unit/template_test.rb +127 -0
  48. metadata +100 -8
  49. data/README.rdoc +0 -89
  50. data/test/generator-subcommand.rb +0 -54
data/.gitignore CHANGED
@@ -1,2 +1,2 @@
1
- doc/*
2
- pkg/*
1
+ pkg/*
2
+ Gemfile.lock
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.1
6
+ - rbx-2
7
+ - jruby
8
+ matrix:
9
+ allow_failures:
10
+ - rvm: rbx-2
11
+ - rvm: jruby
12
+ fast_finish: true
@@ -1,5 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## Version 0.9.0
4
+ * More documentation!
5
+ * More tests! (and CI!)
6
+ * Thor and Tilt updates
7
+ * Add possibility to load external generators from gems (with the `HtmlMockup::Generators::Base.register` method)
8
+ * Partials now automatically prefer templates of the same extension as the parent
9
+ * ERB Templates now support `content_for(:name) do ... end` blocks which can be yielded by `:name` in the layout
10
+ * Multiple load paths for partials are now supported
11
+ * Minor changes and fixes
12
+ * First preparations for version 1.0.0. which will be called **Roger**
13
+
3
14
  ## Version 0.8.4
4
15
  * Fix requirejs processor to clean up the correct paths
5
16
  * Allow typing of Y to rsync instead of full "yes"
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec :name => "html_mockup"
4
+
5
+ gem "rake"
@@ -0,0 +1,95 @@
1
+ # HtmlMockup
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/html_mockup.png)](http://badge.fury.io/rb/html_mockup)
4
+ [![Build Status](https://travis-ci.org/DigitPaint/html_mockup.png?branch=master)](https://travis-ci.org/DigitPaint/html_mockup)
5
+
6
+ ## What is it?
7
+
8
+ HtmlMockup is your friendly front-end development toolbox! It helps you with these 4 things:
9
+
10
+ 1. **Generate** : Set up your projects
11
+ 1. **Serve** : Development server
12
+ 1. **Test** : Test/lint your stuff
13
+ 1. **Release** : Release your code
14
+
15
+ ## Get started
16
+
17
+ We assume you have a working Ruby 1.9.x or higher running.
18
+
19
+ 1. Install HtmlMockup
20
+
21
+ ```shell
22
+ gem install html_mockup
23
+ ```
24
+
25
+ 1. Create a new project
26
+
27
+ ```shell
28
+ mockup generate new PROJECT_DIR
29
+ ```
30
+
31
+ Replace `PROJECT_DIR` with your project name
32
+
33
+ 1. Start the development server
34
+
35
+ ```shell
36
+ mockup serve
37
+ ```
38
+
39
+ Open your webbrowser and go to `http://localhost:9000/`
40
+
41
+ 1. Release your project
42
+
43
+ ```shell
44
+ mockup release
45
+ ```
46
+
47
+ ## Where to go from here?
48
+
49
+ Read more documentation:
50
+
51
+ * [**Templating** Learn the power of HtmlMockup built in templating](doc/templating.md)
52
+ * [**CLI** Learn about the different `mockup` commands](doc/cli.md)
53
+ * [**Mockupfile** Learn how to configure and extend your Project](doc/mockupfile.md)
54
+
55
+ ## Why?
56
+
57
+ When we started with HtmlMockup there was no Grunt/Gulp/whatever and with us being a Ruby shop we wrote HtmlMockup. Since its beginning it has evolved into quite a powerful tool.
58
+
59
+ Why would HtmlMockup be better than any other?
60
+ It's not it just does some things differently.
61
+
62
+ * Ruby
63
+ * Code over configuration
64
+ * Based on little modules, simple to extend
65
+ * Streams & files
66
+ * 4 easy commands separate concerns
67
+
68
+ ## Contributors
69
+
70
+ [View contributors](https://github.com/digitpaint/html_mockup/graphs/contributors)
71
+
72
+ ## License
73
+
74
+ (The MIT License)
75
+
76
+ Copyright (c) 2014 Digitpaint
77
+
78
+ Permission is hereby granted, free of charge, to any person obtaining
79
+ a copy of this software and associated documentation files (the
80
+ 'Software'), to deal in the Software without restriction, including
81
+ without limitation the rights to use, copy, modify, merge, publish,
82
+ distribute, sublicense, and/or sell copies of the Software, and to
83
+ permit persons to whom the Software is furnished to do so, subject to
84
+ the following conditions:
85
+
86
+ The above copyright notice and this permission notice shall be
87
+ included in all copies or substantial portions of the Software.
88
+
89
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
90
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
91
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
92
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
93
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
94
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
95
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -1,4 +1,9 @@
1
- task :test do
2
- ruby "test/unit/release/processors/require_js_test.rb"
3
- ruby "test/unit/release/cleaner_test.rb"
4
- end
1
+ require 'rake/testtask'
2
+
3
+ task :default => [:test]
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs << "test"
7
+ t.test_files = FileList['test/unit/**/*_test.rb']
8
+ t.verbose = true
9
+ end
data/bin/mockup CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  require File.dirname(__FILE__) + "/../lib/html_mockup/cli"
4
4
 
5
- HtmlMockup::Cli.start
5
+ HtmlMockup::Cli::Base.start
@@ -0,0 +1,46 @@
1
+ # Command Line Interface
2
+
3
+ The easiest way to get help is through the commandline by running
4
+
5
+ ```shell
6
+ mockup help
7
+ ```
8
+
9
+ or to get help on a specific subcommand
10
+
11
+ ```shell
12
+ mockup help [subcommand]
13
+ ```
14
+
15
+ ## Generate
16
+
17
+ ```shell
18
+ mockup generate [generator] [options]
19
+ ```
20
+
21
+ ## Serve
22
+
23
+ ```shell
24
+ mockup serve [options]
25
+ ```
26
+
27
+ Starts a webserver (port 9000 by default)
28
+
29
+
30
+ ## Release
31
+
32
+ ```shell
33
+ mockup release [options]
34
+ ```
35
+
36
+ Releases the project
37
+
38
+ ## Global options
39
+
40
+ All commands accept these options.
41
+
42
+ ```
43
+ Options:
44
+ -v, [--verbose] # Set's verbose output
45
+ -h, [--help] # Help
46
+ ```
@@ -0,0 +1,3 @@
1
+ # Mockupfile
2
+
3
+ The mockupfile is where all the project configuration for releasing, serving etc. happens.
@@ -0,0 +1,88 @@
1
+ # Templating
2
+
3
+ ## Directories
4
+
5
+ Before we get started, it's good to know that there are a couple of "special" folders within any HtmlMockup project. Don't worry, you can configure these; they're not hard-coded. The folders are:
6
+
7
+ * **project-path** this is the main directory containing the Mockupfile and all other directories.
8
+ * **html-path** this is the directory where all your HTML/CSS/Javascript will go (in subdirectories of course).
9
+ * **partials-path** this is the directory where all partials reside.
10
+ * **layouts-path** this is the directory where the layouts hang out.
11
+
12
+ The default project tree looks like this:
13
+
14
+ ```
15
+ project-path
16
+ |
17
+ |- html (html-path)
18
+ |
19
+ |- partials (partials-path)
20
+ |
21
+ \- layouts (layouts-path)
22
+ ```
23
+
24
+ Only the html-path has to exist. The others are not required.
25
+
26
+ ## HTML
27
+
28
+ The html-path is actually the root for all you front-end code. This is what will be served as the document-root with `mockup serve` and will be the base for a release when using `mockup release`.
29
+
30
+ In the html-path you can put static files (images, documents, etc.) but also templates. Anything that the [Tilt Engine](https://github.com/rtomayko/tilt) can handle is ok. The only thing Mockup adds is handling for front-matter, layouts and partials.
31
+
32
+ ## Front-matter
33
+
34
+ Every template can optionally start with a bit of front-matter. Front-matter is defined as follows:
35
+
36
+ ```yaml
37
+ ---
38
+ key: value
39
+ ---
40
+ ```
41
+
42
+ Front-matter is parsed as YAML and can contain data to be used in the template, layout or partial. You can access
43
+ these values in the templates (layouts and partials included) by using `document.KEY`.
44
+
45
+ ## Layouts
46
+
47
+ Layouts are basically "wrap" templates. The layout will wrap around the rendered template. In the template front-matter you define what layout it should use by setting the `layout` key.
48
+
49
+ ### An example
50
+
51
+
52
+ #### html/template.html.erb
53
+ ```erb
54
+ ---
55
+ layout: default
56
+ ---
57
+ Template
58
+ ```
59
+
60
+ #### layouts/default.html.erb
61
+ ```erb
62
+ Layout (before)
63
+ <% yield %>
64
+ Layout (after)
65
+ ```
66
+
67
+ #### Results
68
+ This would result in:
69
+
70
+ ```
71
+ Layout (before)
72
+ Template
73
+ Layout (after)
74
+ ```
75
+
76
+ ## Partials
77
+
78
+ Partials are little pieces of template that can be easily reused. You can access the partials throught the `partial("partialpath")` method. You can optionall pass variables to the partial by passing a ruby hash of options as a second parameter. This works like this:
79
+
80
+ ```ruby
81
+ partial("path/to/partial/relative/to/partials-path", {:key => "value"})
82
+ ```
83
+
84
+ In the partial these can be accessed as local variables. So for instance in you `test.html.erb` partial that would look like this:
85
+
86
+ ```erb
87
+ <%= key %>
88
+ ```
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "html_mockup"
5
- s.version = "0.8.4"
5
+ s.version = "0.9.0"
6
6
 
7
7
  s.authors = ["Flurin Egger", "Edwin van der Graaf", "Joran Kapteijns"]
8
8
  s.email = ["info@digitpaint.nl", "flurin@digitpaint.nl"]
@@ -18,8 +18,8 @@ Gem::Specification.new do |s|
18
18
  s.require_paths = ["lib"]
19
19
 
20
20
  s.extra_rdoc_files = [
21
- "README.rdoc"
22
- ]
21
+ "README.md"
22
+ ] + `git ls-files -- {doc}/*`.split("\n")
23
23
 
24
24
  s.rdoc_options = ["--charset=UTF-8"]
25
25
 
@@ -27,7 +27,11 @@ Gem::Specification.new do |s|
27
27
 
28
28
  s.add_dependency("thor", ["~> 0.16.0"])
29
29
  s.add_dependency("rack", [">= 1.0.0"])
30
- s.add_dependency("tilt", ["~> 1.4.0"])
30
+ s.add_dependency("tilt", ["~> 2.0.1"])
31
+ s.add_dependency("mime-types", ["~> 2.2"])
31
32
  s.add_dependency("sass", [">= 0"])
33
+ s.add_dependency("yui-compressor", [">= 0"])
32
34
  s.add_dependency("hpricot", [">= 0.6.4"])
35
+
36
+ s.add_development_dependency("test-unit", "~> 2.5.5")
33
37
  end
@@ -1,4 +1,11 @@
1
1
  require 'rubygems'
2
+
3
+ # Require bundler gems if available
4
+ if Object.const_defined?(:Bundler)
5
+ Bundler.require(:default)
6
+ end
7
+
8
+
2
9
  require 'thor'
3
10
  require 'thor/group'
4
11
 
@@ -8,50 +15,55 @@ include FileUtils
8
15
 
9
16
  require File.dirname(__FILE__) + "/template"
10
17
  require File.dirname(__FILE__) + "/project"
11
- require File.dirname(__FILE__) + "/generators"
12
18
  require File.dirname(__FILE__) + "/w3c_validator"
13
19
 
20
+
14
21
  module HtmlMockup
15
- class Cli < Thor
16
-
17
- class_option :verbose,
18
- :desc => "Set's verbose output",
19
- :aliases => ["-v"],
20
- :default => false,
21
- :type => :boolean
22
-
23
- desc "serve [directory]","Serve directory as HTML, defaults to current directory"
24
- method_options :port => :string, # Defaults to 9000
25
- :html_path => :string, # The document root, defaults to "[directory]/html"
26
- :partial_path => :string, # Defaults to [directory]/partials
27
- :handler => :string, # The handler to use (defaults to mongrel)
28
- :validate => :boolean # Run validation?
29
- def serve(path=".")
30
-
31
- server_options = {}
32
- options.each{|k,v| server_options[k.to_sym] = v }
33
- server_options[:server] = {}
34
- [:port, :handler, :validate].each do |k|
35
- server_options[:server][k] = server_options.delete(k) if server_options.has_key?(k)
36
- end
37
-
38
- # Load the project, it should take care of all the paths
39
- @project = initialize_project(path, server_options)
40
-
41
- server = @project.server
42
- server.set_options(server_options[:server])
43
-
44
- puts "Running HtmlMockup with #{server.handler.inspect} on port #{server.port}"
45
- puts banner(@project)
46
-
47
- server.run!
22
+ module Cli; end
23
+ end
24
+
25
+ require File.dirname(__FILE__) + "/cli/command"
26
+ require File.dirname(__FILE__) + "/cli/serve"
27
+ require File.dirname(__FILE__) + "/cli/release"
28
+ require File.dirname(__FILE__) + "/cli/generate"
29
+
30
+ require File.dirname(__FILE__) + "/generators"
31
+
32
+
33
+ module HtmlMockup
34
+ class Cli::Base < Thor
35
+
36
+ def initialize(*args)
37
+ super
38
+ self.class.project = initialize_project
48
39
  end
49
-
50
- desc "release [directory]", "Create a release for the project"
51
- def release(path=".")
52
- project = initialize_project(path, options)
53
- project.release.run!
40
+
41
+ class << self
42
+ attr_accessor :project
54
43
  end
44
+
45
+ class_option :path,
46
+ :desc => "Project root path",
47
+ :type => :string,
48
+ :required => false,
49
+ :default => "."
50
+
51
+ class_option :html_path,
52
+ :desc => 'The document root, defaults to "[directory]/html"',
53
+ :type => :string
54
+
55
+
56
+ class_option :partial_path,
57
+ :desc => 'Defaults to [directory]/partials',
58
+ :type => :string
59
+
60
+ register Cli::Generate, "generate", "generate [COMMAND]", "Run a generator"
61
+
62
+ register Cli::Serve, "serve", "serve #{Cli::Serve.arguments.map{ |arg| arg.banner }.join(" ")}", Cli::Serve.desc
63
+ self.tasks["serve"].options = Cli::Serve.class_options
64
+
65
+ register Cli::Release, "release", "release #{Cli::Release.arguments.map{ |arg| arg.banner }.join(" ")}", Cli::Release.desc
66
+ self.tasks["release"].options = Cli::Release.class_options
55
67
 
56
68
  desc "validate [directory/file]", "Validates the file or all HTML in directory"
57
69
  method_options :show_valid => :boolean, # Also print a line for each valid file
@@ -83,40 +95,19 @@ module HtmlMockup
83
95
  end
84
96
  end
85
97
 
86
- register HtmlMockup::Generators::New, "new", "new [directory]", ""
87
- # Hack to register our options/description
88
- tasks["new"].options = HtmlMockup::Generators::New.class_options
89
- tasks["new"].description = HtmlMockup::Generators::New.desc
90
-
91
- 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"
92
- method_options :partial_path => :string, # Defaults to [directory]/partials
93
- :filter => :string # What files should be converted defaults to **/*.html
94
- def extract(source_path=".", target_path="../out")
95
- project = initialize_project(source_path)
96
- extractor = HtmlMockup::Extractor.new(project, target_path)
97
- puts "Extracting mockup"
98
- puts banner(project)
99
- extractor.run!
100
- end
101
-
102
98
  protected
103
-
104
- def banner(project)
105
- puts " Html: \"#{project.html_path}\""
106
- puts " Partials: \"#{project.partial_path}\""
107
- end
108
-
99
+
109
100
  # TODO: handle options
110
- def initialize_project(path, options={})
111
-
112
- if((Pathname.new(path) + "../partials").exist?)
101
+ def initialize_project
102
+ if((Pathname.new(options[:path]) + "../partials").exist?)
113
103
  puts "[ERROR]: Don't use the \"html\" path, use the project base path instead"
114
104
  exit(1)
115
105
  end
116
106
 
117
- Project.new(path, {:shell => self.shell}.update(options))
107
+ Project.new(options[:path], {:shell => self.shell}.update(options))
118
108
  end
119
109
 
110
+
120
111
  def w3cvalidate(file)
121
112
  validator = W3CValidator.new(File.read(file))
122
113
  validator.validate!
@@ -128,4 +119,5 @@ module HtmlMockup
128
119
  end
129
120
 
130
121
  end
122
+
131
123
  end