html_mockup 0.8.4 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "roger"
5
+ s.version = "0.0.1"
6
+
7
+ s.authors = ["Flurin Egger", "Edwin van der Graaf", "Joran Kapteijns"]
8
+ s.email = ["info@digitpaint.nl", "flurin@digitpaint.nl"]
9
+ s.homepage = "http://github.com/digitpaint/html_mockup"
10
+ s.summary = "Roger is a set of tools to create self-containing HTML mockups."
11
+ s.licenses = ["MIT"]
12
+
13
+ s.date = Time.now.strftime("%Y-%m-%d")
14
+
15
+ s.files = []
16
+ s.test_files = []
17
+ s.executables = []
18
+ s.require_paths = ["lib"]
19
+
20
+ s.extra_rdoc_files = [
21
+ "README.md"
22
+ ]
23
+
24
+ s.rdoc_options = ["--charset=UTF-8"]
25
+
26
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
27
+
28
+ s.add_dependency("html_mockup", ["~> 0.8.4"])
29
+ end
@@ -3,4 +3,5 @@ source "https://rubygems.org"
3
3
  gem "html_mockup", :path => File.dirname(__FILE__) + "/../../"
4
4
  gem "sass"
5
5
  gem "yui-compressor"
6
- gem "redcarpet"
6
+ gem "redcarpet"
7
+ gem "pry"
@@ -1,35 +1,40 @@
1
1
  PATH
2
2
  remote: /Users/flurin/Projects.local/libraries/html_mockup
3
3
  specs:
4
- html_mockup (0.8.2)
4
+ html_mockup (0.8.4)
5
5
  hpricot (>= 0.6.4)
6
+ mime-types (~> 2.2)
6
7
  rack (>= 1.0.0)
7
8
  sass
8
9
  thor (~> 0.16.0)
9
- tilt (~> 1.4.0)
10
+ tilt (~> 2.0.1)
11
+ yui-compressor
10
12
 
11
13
  GEM
12
14
  remote: https://rubygems.org/
13
15
  specs:
14
- POpen4 (0.1.4)
15
- Platform (>= 0.4.0)
16
- open4
17
- Platform (0.4.0)
16
+ coderay (1.1.0)
18
17
  hpricot (0.8.6)
19
- open4 (1.3.0)
18
+ method_source (0.8.2)
19
+ mime-types (2.2)
20
+ pry (0.9.12.6)
21
+ coderay (~> 1.0)
22
+ method_source (~> 0.8)
23
+ slop (~> 3.4)
20
24
  rack (1.5.2)
21
- redcarpet (2.2.2)
22
- sass (3.2.9)
25
+ redcarpet (3.1.1)
26
+ sass (3.3.5)
27
+ slop (3.5.0)
23
28
  thor (0.16.0)
24
- tilt (1.4.1)
25
- yui-compressor (0.9.6)
26
- POpen4 (>= 0.1.4)
29
+ tilt (2.0.1)
30
+ yui-compressor (0.12.0)
27
31
 
28
32
  PLATFORMS
29
33
  ruby
30
34
 
31
35
  DEPENDENCIES
32
36
  html_mockup!
37
+ pry
33
38
  redcarpet
34
39
  sass
35
40
  yui-compressor
@@ -1,6 +1,9 @@
1
+ require File.dirname(__FILE__) + "/lib/generators/test"
1
2
 
2
3
  mockup.project.options[:verbose] = true;
3
4
 
5
+ mockup.project.partial_path = [mockup.project.path + "partials", mockup.project.path + "partials2"]
6
+
4
7
  mockup.serve do |s|
5
8
  end
6
9
 
@@ -0,0 +1 @@
1
+ Just an index.html
@@ -0,0 +1,17 @@
1
+ ---
2
+ layout : "test"
3
+ title : "Content for"
4
+ ---
5
+ Normal Yield
6
+
7
+ <% content_for :one do %>
8
+ Yield for one <%= "bla" %>
9
+ <% end %>
10
+
11
+ And more normal stuff
12
+
13
+ <% content_for :two do %>
14
+ Yield for two <%= "bla" %>
15
+ <% end %>
16
+
17
+ And the end of the normal stuff
@@ -0,0 +1,3 @@
1
+ Some special characterrrs
2
+
3
+ éᙀ
@@ -0,0 +1,3 @@
1
+ <%= partial "partials-test" %>
2
+
3
+ <%= partial "partials2-test" %>
@@ -22,6 +22,13 @@
22
22
 
23
23
  <h3>MD</h3>
24
24
  <%= partial "test/markdown" %>
25
-
25
+
26
+ <h3>Content for "one"</h3>
27
+ <%= yield :one %>
28
+
29
+
30
+ <h3>Content for "two"</h3>
31
+ <%= yield :two %>
32
+
26
33
  </body>
27
34
  </html>
@@ -0,0 +1 @@
1
+ <%= yield %><%= yield :one %>
@@ -0,0 +1,9 @@
1
+ class TestGenerator < HtmlMockup::Generators::Base
2
+
3
+ def do
4
+ puts "Done!"
5
+ end
6
+
7
+ end
8
+
9
+ HtmlMockup::Generators::Base.register TestGenerator
@@ -0,0 +1 @@
1
+ <%= "erb" %>
@@ -0,0 +1 @@
1
+ partials/partial-test.html.erb
@@ -0,0 +1 @@
1
+ <%= document.test %>
@@ -0,0 +1 @@
1
+ { key: <%= "value" %> }
@@ -0,0 +1 @@
1
+ partials2/partials2-test.html.erb
@@ -0,0 +1,12 @@
1
+ require "./lib/html_mockup/cli.rb"
2
+ require "test/unit"
3
+
4
+ module HtmlMockup
5
+ class CliTest < Test::Unit::TestCase
6
+
7
+ def test_register_generators
8
+ assert_includes Cli::Base.subcommands, "generate"
9
+ end
10
+
11
+ end
12
+ end
@@ -0,0 +1,75 @@
1
+ # Generators register themself on the CLI module
2
+ require "./lib/html_mockup/generators.rb"
3
+ require "test/unit"
4
+
5
+ module CustomGens
6
+ module Generators
7
+
8
+ class MockedGenerator < HtmlMockup::Generators::Base
9
+
10
+ desc "@mocked description"
11
+ argument :path, :type => :string, :required => false, :desc => "Path to generate mockup into"
12
+ argument :another_arg, :type => :string, :required => false, :desc => "Mocked or what?!"
13
+
14
+ def test
15
+ # Somewhat ugly way of checking
16
+ raise NotImplementedError
17
+ end
18
+ end
19
+
20
+ class MockedWithProjectGenerator < HtmlMockup::Generators::Base
21
+
22
+ desc "Returns a project"
23
+ def test
24
+ # Somewhat ugly way of checking
25
+ raise StandardError if @project
26
+ end
27
+ end
28
+
29
+ end
30
+ end
31
+
32
+ module HtmlMockup
33
+ class GeneratorTest < Test::Unit::TestCase
34
+ def setup
35
+ @cli = Cli::Base.new
36
+ end
37
+
38
+ def test_working_project
39
+ HtmlMockup::Generators::Base.register CustomGens::Generators::MockedWithProjectGenerator
40
+ generators = Cli::Generate.new
41
+
42
+ assert_raise StandardError do
43
+ generators.invoke "mockedwithproject"
44
+ end
45
+ end
46
+
47
+ def test_register_generator
48
+ HtmlMockup::Generators::Base.register CustomGens::Generators::MockedGenerator
49
+ assert_includes Cli::Generate.tasks, "mocked"
50
+ assert_equal Cli::Generate.tasks["mocked"].description, "@mocked description"
51
+ assert_equal Cli::Generate.tasks["mocked"].usage, "mocked PATH ANOTHER_ARG"
52
+ end
53
+
54
+ def test_default_generator
55
+ assert_includes Cli::Generate.tasks, "new"
56
+ end
57
+
58
+ def test_generator_generator
59
+ generators = Cli::Generate.new
60
+ name = "tralal"
61
+ path = "./tmp"
62
+ generators.invoke :generator, [name, path]
63
+ assert File.exist? "#{path}/#{name}_generator.rb"
64
+ end
65
+
66
+ def test_invoke_mocked_generator
67
+ HtmlMockup::Generators::Base.register CustomGens::Generators::MockedGenerator
68
+
69
+ generators = Cli::Generate.new
70
+ assert_raise NotImplementedError do
71
+ generators.invoke :mocked
72
+ end
73
+ end
74
+ end
75
+ end
@@ -4,29 +4,34 @@ require "test/unit"
4
4
 
5
5
  class CleanerTest < Test::Unit::TestCase
6
6
 
7
+ def setup
8
+ @base = File.dirname(__FILE__) + "/../../project"
9
+ end
10
+
7
11
  def test_only_clean_inside_build_path_relative
8
- path = "processors"
9
- cleaner = HtmlMockup::Release::Cleaner.new(path)
10
- inside_build_path = cleaner.send :is_inside_build_path, File.dirname(__FILE__), path
12
+
13
+ cleaner = HtmlMockup::Release::Cleaner.new(@base)
14
+ inside_build_path = cleaner.send :is_inside_build_path, @base, @base + "/html/formats"
11
15
 
12
16
  assert(inside_build_path, "Only delete content inside build_path")
13
17
  end
14
18
 
15
19
  def test_only_clean_inside_build_path_absolute
16
- path = Pathname.new(File.dirname(__FILE__) + "/processors").realpath.to_s
20
+ path = Pathname.new(@base).realpath.to_s
17
21
  cleaner = HtmlMockup::Release::Cleaner.new(path)
18
- inside_build_path = cleaner.send :is_inside_build_path, File.dirname(__FILE__), path
22
+
23
+ inside_build_path = cleaner.send :is_inside_build_path, path, @base + "/html/formats"
19
24
 
20
25
  assert(inside_build_path, "Only delete content inside build_path")
21
26
  end
22
27
 
23
28
 
24
29
  def test_dont_clean_outside_build_path
25
- path = "../../../lib"
30
+ path = File.dirname(__FILE__)
26
31
  cleaner = HtmlMockup::Release::Cleaner.new(path)
27
32
 
28
33
  assert_raise RuntimeError do
29
- inside_build_path = cleaner.send :is_inside_build_path, File.dirname(__FILE__), path
34
+ inside_build_path = cleaner.send :is_inside_build_path, path, @base + "/html/formats"
30
35
  end
31
36
 
32
37
  end
@@ -35,7 +40,7 @@ class CleanerTest < Test::Unit::TestCase
35
40
  path = "bla"
36
41
  cleaner = HtmlMockup::Release::Cleaner.new(path)
37
42
 
38
- assert !cleaner.send(:is_inside_build_path, File.dirname(__FILE__), path), "Failed on nonexistent directories/files"
43
+ assert !cleaner.send(:is_inside_build_path, @base + "/html/formats", path), "Failed on nonexistent directories/files"
39
44
 
40
45
  end
41
46
 
@@ -0,0 +1,92 @@
1
+ # Generators register themself on the CLI module
2
+ require "./lib/html_mockup/resolver.rb"
3
+ require "test/unit"
4
+
5
+ module HtmlMockup
6
+ class ResolverTest < Test::Unit::TestCase
7
+ def setup
8
+ @base = Pathname.new(File.dirname(__FILE__) + "/../project/html")
9
+ @resolver = HtmlMockup::Resolver.new(@base)
10
+ end
11
+
12
+ def test_find_template_path
13
+ assert_equal @resolver.find_template("formats/mockup.html"), @base + "formats/mockup.html"
14
+
15
+ # This should not be found on it's own as it will be processed
16
+ assert_equal @resolver.find_template("formats/markdown.md"), nil
17
+ end
18
+
19
+ def test_find_template_index_path
20
+ assert_equal @resolver.find_template("formats"), @base + "formats/index.html"
21
+ end
22
+
23
+ def test_find_template_html_without_extension
24
+ assert_equal @resolver.find_template("formats/index"), @base + "formats/index.html"
25
+ assert_equal @resolver.find_template("formats/erb"), @base + "formats/erb.html.erb"
26
+ end
27
+
28
+ def test_find_template_with_template_extension
29
+ assert_equal @resolver.find_template("formats/markdown"), @base + "formats/markdown.md"
30
+ end
31
+
32
+ def test_find_template_with_double_extensions
33
+ assert_equal @resolver.find_template("formats/erb"), @base + "formats/erb.html.erb"
34
+ assert_equal @resolver.find_template("formats/erb.html"), @base + "formats/erb.html.erb"
35
+
36
+ assert_equal @resolver.find_template("formats/json.json"), @base + "formats/json.json.erb"
37
+ end
38
+
39
+ def test_find_template_with_preferred_extension
40
+ assert_equal @resolver.find_template("formats/json", :preferred_extension => "json"), @base + "formats/json.json.erb"
41
+ end
42
+
43
+ def test_find_template_exact_match
44
+ # TODO
45
+ end
46
+
47
+ def test_path_to_url
48
+ assert_equal @resolver.path_to_url(@base + "formats/erb.html.erb"), "/formats/erb.html.erb"
49
+ end
50
+
51
+ def test_path_to_url_relative_to_relative_path
52
+ assert_equal @resolver.path_to_url(@base + "formats/erb.html.erb", "../front_matter/erb.html.erb"), "../formats/erb.html.erb"
53
+ end
54
+
55
+ def test_path_to_url_relative_to_absolute_path
56
+ assert_equal @resolver.path_to_url(@base + "formats/erb.html.erb", @base.realpath + "front_matter/erb.html.erb"), "../formats/erb.html.erb"
57
+ end
58
+
59
+ end
60
+
61
+ class ResolverMultipleTest < Test::Unit::TestCase
62
+ def setup
63
+ @base = Pathname.new(File.dirname(__FILE__) + "/../project")
64
+ @resolver = HtmlMockup::Resolver.new([@base + "html", @base + "partials"])
65
+ end
66
+
67
+ def test_add_load_path
68
+ @resolver.load_paths << @base + "henk"
69
+
70
+ assert_equal @resolver.load_paths, [@base + "html", @base + "partials", @base + "henk"]
71
+ end
72
+
73
+ def test_find_template_path
74
+ assert_equal @resolver.find_template("formats/index"), @base + "html/formats/index.html"
75
+ assert_equal @resolver.find_template("test/simple"), @base + "partials/test/simple.html.erb"
76
+ end
77
+
78
+ def test_find_template_path_ordered
79
+ assert_equal @resolver.find_template("formats/erb"), @base + "html/formats/erb.html.erb"
80
+
81
+ @resolver.load_paths.reverse!
82
+
83
+ assert_equal @resolver.find_template("formats/erb"), @base + "partials/formats/erb.html.erb"
84
+ end
85
+
86
+
87
+
88
+
89
+
90
+ end
91
+
92
+ end
@@ -0,0 +1,127 @@
1
+ # encoding: UTF-8
2
+ # Generators register themself on the CLI module
3
+ require "./lib/html_mockup/template.rb"
4
+ require "test/unit"
5
+
6
+ module HtmlMockup
7
+ class TemplateTest < Test::Unit::TestCase
8
+ def setup
9
+ @base = Pathname.new(File.dirname(__FILE__) + "/../project")
10
+ @config = {
11
+ :partials_path => @base + "partials",
12
+ :layouts_path => @base + "layouts"
13
+ }
14
+ @template_path = @base + "html"
15
+ end
16
+
17
+ def test_encoding
18
+
19
+ end
20
+
21
+ # Extension
22
+ def test_source_extension
23
+ mime_types = {
24
+ "html" => "html",
25
+ "html.erb" => "html.erb",
26
+ "css.erb" => "css.erb",
27
+ "json.erb" => "json.erb",
28
+ "sjon.json.erb" => "json.erb",
29
+ "js.erb" => "js.erb"
30
+ }
31
+
32
+ mime_types.each do |ext, ext_out|
33
+ assert_equal ext_out, Template.new("", @config.update(:source_path => @base + "html/file.#{ext}")).source_extension
34
+ end
35
+ end
36
+
37
+ def test_target_extension
38
+ mime_types = {
39
+ "html" => "html",
40
+ "html.erb" => "html",
41
+ "css.erb" => "css",
42
+ "json.erb" => "json",
43
+ "js.erb" => "js"
44
+ }
45
+
46
+ mime_types.each do |ext, ext_out|
47
+ assert_equal ext_out, Template.new("", @config.update(:source_path => @base + "html/file.#{ext}")).target_extension
48
+ end
49
+ end
50
+
51
+
52
+ # Mime type
53
+ def test_target_mime_type
54
+ mime_types = {
55
+ "html" => "text/html",
56
+ "html.erb" => "text/html",
57
+ "css.erb" => "text/css",
58
+ "json.erb" => "application/json"
59
+ }
60
+
61
+ mime_types.each do |ext, mime|
62
+ assert_equal mime, Template.new("", @config.update(:source_path => @base + "html/file.#{ext}")).target_mime_type
63
+ end
64
+ end
65
+
66
+ # Front-matter
67
+
68
+ def test_front_matter_partial_access
69
+ template = Template.new("---\ntest: yay!\n---\n<%= partial 'test/front_matter' %>", @config.update(:source_path => @base + "html/test.html.erb"))
70
+ assert_equal template.render, "yay!"
71
+ end
72
+
73
+ # Partials
74
+
75
+ def test_encoding_in_partials
76
+ end
77
+
78
+ def test_partial
79
+ template = Template.new("<%= partial 'test/simple' %>", @config.update(:source_path => @base + "html/test.html.erb"))
80
+ assert_equal template.render, "ERB"
81
+
82
+ template = Template.new("<%= partial 'test/simple.html' %>", @config.update(:source_path => @base + "html/test.erb"))
83
+ assert_equal template.render, "ERB"
84
+ end
85
+
86
+ def test_partial_with_double_template_extensions
87
+ template = Template.new("<%= partial 'test/json.json' %>", @config.update(:source_path => @base + "html/test.erb"))
88
+ assert_equal template.render, "{ key: value }"
89
+ end
90
+
91
+ def test_partial_with_preferred_extension
92
+ template = Template.new("<%= partial 'test/json' %>", @config.update(:source_path => @base + "html/test.html.erb"))
93
+ assert_raise(ArgumentError) {
94
+ template.render
95
+ }
96
+
97
+ template = Template.new("<%= partial 'test/json' %>", @config.update(:source_path => @base + "html/test.json.erb"))
98
+ assert_equal template.render, "{ key: value }"
99
+
100
+ end
101
+
102
+ # Content for parts
103
+
104
+ def test_content_for_not_returning_in_template
105
+ content_for_block = 'B<% content_for :one do %><%= "one" %><% end %>A'
106
+
107
+ template = Template.new(content_for_block, @config.update(:source_path => @base + "html/test.erb"))
108
+ assert_equal template.render, "BA"
109
+ end
110
+
111
+ def test_content_for_yield_in_layout
112
+ content_for_block = "---\nlayout: \"yield\"\n---\nB<% content_for :one do %><%= \"one\" %><% end %>A"
113
+
114
+ template = Template.new(content_for_block, @config.update(:source_path => @base + "html/test.html.erb"))
115
+ assert_equal template.render, "BAone"
116
+ end
117
+
118
+ def test_content_for_yield_in_layout_without_content_for
119
+ content_for_block = "---\nlayout: \"yield\"\n---\nBA"
120
+
121
+ template = Template.new(content_for_block, @config.update(:source_path => @base + "html/test.html.erb"))
122
+ assert_equal template.render, "BA"
123
+ end
124
+
125
+
126
+ end
127
+ end