express_templates 0.2.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 (81) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +53 -0
  4. data/Rakefile +32 -0
  5. data/lib/express_templates/component.rb +92 -0
  6. data/lib/express_templates/components/html_tag.rb +36 -0
  7. data/lib/express_templates/components/wrapper.rb +51 -0
  8. data/lib/express_templates/components/yielder.rb +21 -0
  9. data/lib/express_templates/components.rb +8 -0
  10. data/lib/express_templates/expander.rb +116 -0
  11. data/lib/express_templates/html5_emitter.rb +45 -0
  12. data/lib/express_templates/renderer.rb +16 -0
  13. data/lib/express_templates/template/handler.rb +15 -0
  14. data/lib/express_templates/version.rb +3 -0
  15. data/lib/express_templates.rb +12 -0
  16. data/lib/tasks/gara_tasks.rake +4 -0
  17. data/test/component_test.rb +77 -0
  18. data/test/dummy/Rakefile +6 -0
  19. data/test/dummy/app/assets/javascripts/application.js +13 -0
  20. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  21. data/test/dummy/app/controllers/application_controller.rb +5 -0
  22. data/test/dummy/app/controllers/hello_controller.rb +5 -0
  23. data/test/dummy/app/helpers/application_helper.rb +2 -0
  24. data/test/dummy/app/views/hello/show.html.et +5 -0
  25. data/test/dummy/app/views/layouts/application.html.et +15 -0
  26. data/test/dummy/bin/bundle +3 -0
  27. data/test/dummy/bin/rails +4 -0
  28. data/test/dummy/bin/rake +4 -0
  29. data/test/dummy/config/application.rb +26 -0
  30. data/test/dummy/config/boot.rb +5 -0
  31. data/test/dummy/config/environment.rb +5 -0
  32. data/test/dummy/config/environments/development.rb +37 -0
  33. data/test/dummy/config/environments/production.rb +82 -0
  34. data/test/dummy/config/environments/test.rb +39 -0
  35. data/test/dummy/config/initializers/assets.rb +8 -0
  36. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  37. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  38. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  39. data/test/dummy/config/initializers/inflections.rb +16 -0
  40. data/test/dummy/config/initializers/mime_types.rb +4 -0
  41. data/test/dummy/config/initializers/session_store.rb +3 -0
  42. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  43. data/test/dummy/config/locales/en.yml +23 -0
  44. data/test/dummy/config/routes.rb +4 -0
  45. data/test/dummy/config/secrets.yml +22 -0
  46. data/test/dummy/config.ru +4 -0
  47. data/test/dummy/log/development.log +6478 -0
  48. data/test/dummy/log/test.log +20859 -0
  49. data/test/dummy/public/404.html +67 -0
  50. data/test/dummy/public/422.html +67 -0
  51. data/test/dummy/public/500.html +66 -0
  52. data/test/dummy/public/favicon.ico +0 -0
  53. data/test/dummy/test/controllers/hello_controller_test.rb +14 -0
  54. data/test/dummy/test/helpers/hello_helper_test.rb +4 -0
  55. data/test/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  56. data/test/dummy/tmp/cache/assets/development/sprockets/219e4ef52e71a2dd3142d36271626492 +0 -0
  57. data/test/dummy/tmp/cache/assets/development/sprockets/29331726baea36717bf28565c0be1881 +0 -0
  58. data/test/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  59. data/test/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  60. data/test/dummy/tmp/cache/assets/development/sprockets/4584795e7f513db14ffca10dab44759e +0 -0
  61. data/test/dummy/tmp/cache/assets/development/sprockets/72a227156d935c44e2aad8718b3952fb +0 -0
  62. data/test/dummy/tmp/cache/assets/development/sprockets/cfea650552ed221f83ea2c8fc3198c53 +0 -0
  63. data/test/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  64. data/test/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  65. data/test/dummy/tmp/cache/assets/development/sprockets/e27275f4020fd1fc40de79a1e5db4c96 +0 -0
  66. data/test/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  67. data/test/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  68. data/test/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  69. data/test/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  70. data/test/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  71. data/test/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  72. data/test/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  73. data/test/expander_stack_test.rb +41 -0
  74. data/test/expander_test.rb +56 -0
  75. data/test/fixtures/a_big_page.html +595 -0
  76. data/test/gara_test.rb +19 -0
  77. data/test/handler_test.rb +122 -0
  78. data/test/performance_test.rb +93 -0
  79. data/test/test_helper.rb +17 -0
  80. data/test/wrapper_test.rb +23 -0
  81. metadata +271 -0
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/404.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The page you were looking for doesn't exist.</h1>
62
+ <p>You may have mistyped the address or the page may have moved.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/422.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The change you wanted was rejected.</h1>
62
+ <p>Maybe you tried to change something you didn't have access to.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,66 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/500.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>We're sorry, but something went wrong.</h1>
62
+ </div>
63
+ <p>If you are the application owner check the logs for more information.</p>
64
+ </div>
65
+ </body>
66
+ </html>
File without changes
@@ -0,0 +1,14 @@
1
+ require 'test_helper'
2
+
3
+ class HelloControllerTest < ActionController::TestCase
4
+
5
+ test "should get show" do
6
+ get :show
7
+ assert_response :success
8
+ # puts @response.body
9
+ assert_match /<h1>Hi there<\/h1>/, @response.body
10
+ assert_match %Q(<link data-turbolinks-track="true" href="/assets/application.css" media="all" rel="stylesheet" />), @response.body
11
+ assert_no_match %Q(Dummy ShowDummy Show), @response.body
12
+ end
13
+
14
+ end
@@ -0,0 +1,4 @@
1
+ require 'test_helper'
2
+
3
+ class HelloHelperTest < ActionView::TestCase
4
+ end
@@ -0,0 +1,41 @@
1
+ require 'test_helper'
2
+
3
+ class ExpanderStackTest < ActiveSupport::TestCase
4
+
5
+ def new_stack
6
+ ExpressTemplates::Expander::Stack.new
7
+ end
8
+
9
+ test "#current is empty" do
10
+ assert_empty new_stack.current
11
+ end
12
+
13
+ test "#<< adds something to the current" do
14
+ stack = new_stack
15
+ stack << 'foo'
16
+ assert_equal ['foo'], stack.current
17
+ end
18
+
19
+ test "#all returns the stack" do
20
+ assert_equal [[]], new_stack.all
21
+ end
22
+
23
+ test "#descend! adds a level to the stack and updates current" do
24
+ stack = new_stack
25
+ stack << 'foo'
26
+ level = stack.descend!
27
+ assert_equal 2, stack.all.count
28
+ assert_equal [], stack.current
29
+ assert_equal 1, level
30
+ end
31
+
32
+ test "#ascend!" do
33
+ stack = new_stack
34
+ stack << 'foo'
35
+ level_1 = stack.descend!
36
+ level_2 = stack.descend!
37
+ level = stack.ascend!
38
+ assert_equal level_1, level
39
+ end
40
+
41
+ end
@@ -0,0 +1,56 @@
1
+ require 'test_helper'
2
+
3
+ class ExpanderTest < ActiveSupport::TestCase
4
+
5
+ class Foo < ExpressTemplates::Component ; end
6
+ class Bar < ExpressTemplates::Component ; end
7
+ class Baz < ExpressTemplates::Component ; end
8
+
9
+ ExpressTemplates::Expander.register_macros_for(Foo,Bar,Baz)
10
+
11
+ test ".expand returns a string" do
12
+ source = "foo"
13
+ result = ExpressTemplates::Expander.expand(nil, source)
14
+ assert_kind_of String, result
15
+ end
16
+
17
+ test "#expand returns an array containing a component" do
18
+ source = "foo"
19
+ result = ExpressTemplates::Expander.new(nil).expand(source)
20
+ assert_kind_of ExpressTemplates::Component, result.first
21
+ end
22
+
23
+ test "#expand of 'foo { foo } returns a component with a child component" do
24
+ source = 'foo { foo }'
25
+ result = ExpressTemplates::Expander.new(nil).expand(source)
26
+ assert_kind_of Foo, result.first.children.first
27
+ end
28
+
29
+ test "#expand of 'foo { bar ; baz } returns a component with two children" do
30
+ source = 'foo { bar ; baz }'
31
+ result = ExpressTemplates::Expander.new(nil).expand(source)
32
+ assert_equal 2, result.first.children.size
33
+ assert_kind_of Bar, result.first.children.first
34
+ assert_kind_of Baz, result.first.children.last
35
+ end
36
+
37
+ test "#expand of macros with args returns a component with two children" do
38
+ source = 'foo { bar(fiz: "buzz") ; baz }'
39
+ result = ExpressTemplates::Expander.new(nil).expand(source)
40
+ assert_equal 2, result.first.children.size
41
+ assert_kind_of Bar, result.first.children.first
42
+ assert_kind_of Baz, result.first.children.last
43
+ end
44
+
45
+ test "#expand correctly allocated helpers and parameters xxx" do
46
+ source = 'helper ; foo { buzz }'
47
+ result = ExpressTemplates::Expander.new(nil).expand(source)
48
+ assert_equal 0, result.first.children.size
49
+ assert_equal 1, result[1].children.size
50
+ assert_kind_of ExpressTemplates::Components::Wrapper, result.first
51
+ assert_kind_of Foo, result[1]
52
+ assert_kind_of ExpressTemplates::Components::Wrapper, result[1].children.first
53
+ end
54
+
55
+
56
+ end