middleman-apps 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/.rubocop.yml +2 -1
  4. data/Gemfile +4 -0
  5. data/{LICENSE.txt → LICENSE} +0 -0
  6. data/README.md +166 -40
  7. data/features/e_asset_hash.feature +17 -0
  8. data/features/{directory_indexes.feature → e_directory_indexes.feature} +14 -16
  9. data/features/e_relative_assets.feature +17 -0
  10. data/features/f_code_reloading.feature +134 -0
  11. data/features/f_metadata.feature +25 -0
  12. data/features/{not_found_rack.feature → f_not_found.feature} +12 -22
  13. data/features/f_options.feature +39 -0
  14. data/features/step_definitions/capybara_steps.rb +18 -0
  15. data/features/step_definitions/mechanize_steps.rb +19 -0
  16. data/features/step_definitions/rack_app_steps.rb +4 -2
  17. data/features/support/aruba.rb +22 -0
  18. data/features/support/env.rb +0 -14
  19. data/features/support/helpers.rb +11 -0
  20. data/features/support/mechanize.rb +32 -0
  21. data/features/support/poltegeist.rb +35 -0
  22. data/features/v_activating.feature +74 -0
  23. data/features/v_building.feature +31 -0
  24. data/features/v_inheriting_from.feature +38 -0
  25. data/fixtures/asset_hash/apps/ignored_app.rb +10 -0
  26. data/fixtures/asset_hash/apps/test_app.rb +11 -0
  27. data/fixtures/asset_hash/config.rb +2 -0
  28. data/fixtures/asset_hash/source/error.html.erb +2 -0
  29. data/fixtures/{complex-app → asset_hash}/source/index.html.erb +0 -0
  30. data/fixtures/asset_hash/source/layouts/layout.erb +12 -0
  31. data/fixtures/asset_hash/source/layouts/page.erb +6 -0
  32. data/fixtures/asset_hash/source/stylesheets/style.css.scss.erb +5 -0
  33. data/fixtures/dir_index/apps/ignored_app.rb +10 -0
  34. data/fixtures/dir_index/apps/test_app.rb +10 -0
  35. data/fixtures/dir_index/config.rb +2 -0
  36. data/fixtures/{simple-app → dir_index}/source/index.html.erb +0 -0
  37. data/fixtures/mount_path/apps/test_app.rb +10 -0
  38. data/fixtures/mount_path/config.rb +1 -0
  39. data/fixtures/{complex-app/build/index.html → mount_path/source/index.html.erb} +0 -0
  40. data/fixtures/real_world/apps/awesome_api.rb +40 -0
  41. data/fixtures/{complex-app → real_world}/apps/child_app.rb +15 -2
  42. data/fixtures/{complex-app/apps/test_app.rb → real_world/apps/ignored_app.rb} +2 -2
  43. data/fixtures/real_world/apps/no_namespace.rb +8 -0
  44. data/fixtures/real_world/apps/test_app.rb +16 -0
  45. data/fixtures/real_world/config.rb +13 -0
  46. data/fixtures/real_world/source/apps.html.erb +14 -0
  47. data/fixtures/real_world/source/custom.html.erb +1 -0
  48. data/fixtures/{simple-app/build/index.html → real_world/source/index.html.erb} +0 -0
  49. data/fixtures/real_world/source/layouts/_partial.erb +1 -0
  50. data/fixtures/real_world/source/layouts/layout.erb +11 -0
  51. data/fixtures/real_world/source/layouts/page.erb +6 -0
  52. data/fixtures/real_world/source/layouts/test.html.markdown.erb +3 -0
  53. data/fixtures/relative_assets/apps/ignored_app.rb +10 -0
  54. data/fixtures/relative_assets/apps/test_app.rb +11 -0
  55. data/fixtures/relative_assets/config.rb +2 -0
  56. data/fixtures/relative_assets/source/error.html.erb +2 -0
  57. data/fixtures/relative_assets/source/index.html.erb +2 -0
  58. data/fixtures/relative_assets/source/layouts/layout.erb +12 -0
  59. data/fixtures/relative_assets/source/layouts/page.erb +6 -0
  60. data/fixtures/relative_assets/source/stylesheets/style.css.scss.erb +5 -0
  61. data/fixtures/simple/apps/ignored_app.rb +10 -0
  62. data/fixtures/simple/apps/test_app.rb +10 -0
  63. data/fixtures/simple/config.rb +1 -0
  64. data/fixtures/simple/source/index.html.erb +2 -0
  65. data/lib/middleman/apps.rb +26 -7
  66. data/lib/middleman/apps/base.rb +71 -15
  67. data/lib/middleman/apps/extension.rb +34 -158
  68. data/lib/middleman/apps/version.rb +2 -1
  69. data/lib/middleman/sitemap/app_collection.rb +225 -0
  70. data/lib/middleman/sitemap/app_resource.rb +61 -0
  71. metadata +77 -31
  72. data/features/activation.feature +0 -53
  73. data/features/build.feature +0 -20
  74. data/features/child_app.feature +0 -18
  75. data/features/complex_app.feature +0 -66
  76. data/features/not_found_server.feature +0 -8
  77. data/features/verbose.feature +0 -23
  78. data/fixtures/complex-app/apps/awesome_api.rb +0 -11
  79. data/fixtures/complex-app/build/error.html +0 -1
  80. data/fixtures/complex-app/config.rb +0 -1
  81. data/fixtures/simple-app/apps/test_app.rb +0 -8
  82. data/fixtures/simple-app/build/error.html +0 -1
  83. data/fixtures/simple-app/config.rb +0 -1
@@ -0,0 +1,61 @@
1
+ module Middleman
2
+ module Sitemap
3
+ # Base app resource that inherits from Sitemap Resource.
4
+ #
5
+ class AppResource < Resource
6
+ def self.find_by_klass(klass, app)
7
+ app.sitemap.resources.detect do |res|
8
+ res.is_a?(self) && res.locals[:klass].name == klass.name
9
+ end
10
+ end
11
+
12
+ def self.find_by_path(path, app)
13
+ app.sitemap.resources.detect do |res|
14
+ res.is_a?(self) && res.source_file.to_s == path.to_s
15
+ end
16
+ end
17
+
18
+ # Get class for this child app.
19
+ #
20
+ # @return [Class] class for the child app
21
+ #
22
+ def klass
23
+ locals[:klass]
24
+ end
25
+
26
+ def title
27
+ locals[:title] || path.to_s.titleize
28
+ end
29
+
30
+ def description
31
+ str = locals[:description].to_s
32
+ locals[:description] = str.gsub(/^#{str.scan(/^[ \t]+(?=\S)/).min}/, '')
33
+ end
34
+
35
+ def update_locals(key, val)
36
+ locals[key.to_sym] = val
37
+ end
38
+
39
+ def routes
40
+ locals[:routes] || []
41
+ end
42
+
43
+ def html_description
44
+ return locals[:html_description] if locals[:html_description]
45
+ html = Tilt['markdown'].new { description }.render(self)
46
+ locals[:html_description] = html
47
+ end
48
+
49
+ def render(opts = {}, locs = {})
50
+ md = metadata
51
+ locs = md[:locals].deep_merge(locs)
52
+ opts = md[:options].deep_merge(opts)
53
+ locs[:current_path] ||= destination_path
54
+
55
+ layout = "layouts/#{opts.delete(:layout)}"
56
+ context = @app.template_context_class.new(@app, locs, opts)
57
+ context.render :middleman, layout, opts.merge(locals: locs)
58
+ end
59
+ end
60
+ end
61
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: middleman-apps
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nikhil Gupta
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-10 00:00:00.000000000 Z
11
+ date: 2017-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: middleman-core
@@ -77,37 +77,75 @@ files:
77
77
  - ".rubocop.yml"
78
78
  - ".travis.yml"
79
79
  - Gemfile
80
- - LICENSE.txt
80
+ - LICENSE
81
81
  - README.md
82
82
  - Rakefile
83
- - features/activation.feature
84
- - features/build.feature
85
- - features/child_app.feature
86
- - features/complex_app.feature
87
- - features/directory_indexes.feature
88
- - features/not_found_rack.feature
89
- - features/not_found_server.feature
83
+ - features/e_asset_hash.feature
84
+ - features/e_directory_indexes.feature
85
+ - features/e_relative_assets.feature
86
+ - features/f_code_reloading.feature
87
+ - features/f_metadata.feature
88
+ - features/f_not_found.feature
89
+ - features/f_options.feature
90
+ - features/step_definitions/capybara_steps.rb
91
+ - features/step_definitions/mechanize_steps.rb
90
92
  - features/step_definitions/rack_app_steps.rb
93
+ - features/support/aruba.rb
91
94
  - features/support/env.rb
92
- - features/verbose.feature
93
- - fixtures/complex-app/apps/awesome_api.rb
94
- - fixtures/complex-app/apps/child_app.rb
95
- - fixtures/complex-app/apps/test_app.rb
96
- - fixtures/complex-app/build/error.html
97
- - fixtures/complex-app/build/index.html
98
- - fixtures/complex-app/config.rb
99
- - fixtures/complex-app/source/index.html.erb
100
- - fixtures/simple-app/apps/test_app.rb
101
- - fixtures/simple-app/build/error.html
102
- - fixtures/simple-app/build/index.html
103
- - fixtures/simple-app/config.rb
104
- - fixtures/simple-app/source/index.html.erb
95
+ - features/support/helpers.rb
96
+ - features/support/mechanize.rb
97
+ - features/support/poltegeist.rb
98
+ - features/v_activating.feature
99
+ - features/v_building.feature
100
+ - features/v_inheriting_from.feature
101
+ - fixtures/asset_hash/apps/ignored_app.rb
102
+ - fixtures/asset_hash/apps/test_app.rb
103
+ - fixtures/asset_hash/config.rb
104
+ - fixtures/asset_hash/source/error.html.erb
105
+ - fixtures/asset_hash/source/index.html.erb
106
+ - fixtures/asset_hash/source/layouts/layout.erb
107
+ - fixtures/asset_hash/source/layouts/page.erb
108
+ - fixtures/asset_hash/source/stylesheets/style.css.scss.erb
109
+ - fixtures/dir_index/apps/ignored_app.rb
110
+ - fixtures/dir_index/apps/test_app.rb
111
+ - fixtures/dir_index/config.rb
112
+ - fixtures/dir_index/source/index.html.erb
113
+ - fixtures/mount_path/apps/test_app.rb
114
+ - fixtures/mount_path/config.rb
115
+ - fixtures/mount_path/source/index.html.erb
116
+ - fixtures/real_world/apps/awesome_api.rb
117
+ - fixtures/real_world/apps/child_app.rb
118
+ - fixtures/real_world/apps/ignored_app.rb
119
+ - fixtures/real_world/apps/no_namespace.rb
120
+ - fixtures/real_world/apps/test_app.rb
121
+ - fixtures/real_world/config.rb
122
+ - fixtures/real_world/source/apps.html.erb
123
+ - fixtures/real_world/source/custom.html.erb
124
+ - fixtures/real_world/source/index.html.erb
125
+ - fixtures/real_world/source/layouts/_partial.erb
126
+ - fixtures/real_world/source/layouts/layout.erb
127
+ - fixtures/real_world/source/layouts/page.erb
128
+ - fixtures/real_world/source/layouts/test.html.markdown.erb
129
+ - fixtures/relative_assets/apps/ignored_app.rb
130
+ - fixtures/relative_assets/apps/test_app.rb
131
+ - fixtures/relative_assets/config.rb
132
+ - fixtures/relative_assets/source/error.html.erb
133
+ - fixtures/relative_assets/source/index.html.erb
134
+ - fixtures/relative_assets/source/layouts/layout.erb
135
+ - fixtures/relative_assets/source/layouts/page.erb
136
+ - fixtures/relative_assets/source/stylesheets/style.css.scss.erb
137
+ - fixtures/simple/apps/ignored_app.rb
138
+ - fixtures/simple/apps/test_app.rb
139
+ - fixtures/simple/config.rb
140
+ - fixtures/simple/source/index.html.erb
105
141
  - lib/middleman.rb
106
142
  - lib/middleman/apps.rb
107
143
  - lib/middleman/apps/base.rb
108
144
  - lib/middleman/apps/extension.rb
109
145
  - lib/middleman/apps/rack_contrib.rb
110
146
  - lib/middleman/apps/version.rb
147
+ - lib/middleman/sitemap/app_collection.rb
148
+ - lib/middleman/sitemap/app_resource.rb
111
149
  - middleman-apps.gemspec
112
150
  homepage: https://github.com/nikhgupta/middleman-apps
113
151
  licenses: []
@@ -133,13 +171,21 @@ signing_key:
133
171
  specification_version: 4
134
172
  summary: Middleman extension to run dynamic pages using Sinatra
135
173
  test_files:
136
- - features/activation.feature
137
- - features/build.feature
138
- - features/child_app.feature
139
- - features/complex_app.feature
140
- - features/directory_indexes.feature
141
- - features/not_found_rack.feature
142
- - features/not_found_server.feature
174
+ - features/e_asset_hash.feature
175
+ - features/e_directory_indexes.feature
176
+ - features/e_relative_assets.feature
177
+ - features/f_code_reloading.feature
178
+ - features/f_metadata.feature
179
+ - features/f_not_found.feature
180
+ - features/f_options.feature
181
+ - features/step_definitions/capybara_steps.rb
182
+ - features/step_definitions/mechanize_steps.rb
143
183
  - features/step_definitions/rack_app_steps.rb
184
+ - features/support/aruba.rb
144
185
  - features/support/env.rb
145
- - features/verbose.feature
186
+ - features/support/helpers.rb
187
+ - features/support/mechanize.rb
188
+ - features/support/poltegeist.rb
189
+ - features/v_activating.feature
190
+ - features/v_building.feature
191
+ - features/v_inheriting_from.feature
@@ -1,53 +0,0 @@
1
- Feature: Activating MiddlemanApps
2
-
3
- Scenario: Without `middleman-apps`
4
- Given a fixture app "simple-app"
5
- And a file named "config.rb" with:
6
- """
7
- """
8
- And the Server is running at "simple-app"
9
- When I go to "/"
10
- Then I should see "<h1>Middleman</h1>"
11
- When I go to "/test-app"
12
- Then the status code should be "404"
13
- And I should see "<h1>File Not Found</h1>"
14
-
15
- Scenario: Without `middleman-apps` with Rack
16
- Given a fixture app "simple-app"
17
- And a file named "config.rb" with:
18
- """
19
- require 'sinatra'
20
- require_relative 'apps/test_app'
21
- map("/test-app") { run TestApp }
22
- """
23
- And the Server is running at "simple-app"
24
- When I go to "/"
25
- Then I should see "<h1>Middleman</h1>"
26
- When I go to "/test-app"
27
- Then I should see "fail"
28
- When I go to "/test-app/?test=1"
29
- Then I should see "pass"
30
-
31
- Scenario: With `middleman-apps`
32
- Given a fixture app "simple-app"
33
- And a file named "config.rb" with:
34
- """
35
- activate :apps
36
- """
37
- And the Server is running at "simple-app"
38
- When I go to "/"
39
- Then I should see "<h1>Middleman</h1>"
40
- When I go to "/test-app"
41
- Then I should see "fail"
42
- When I go to "/test-app/?test=1"
43
- Then I should see "pass"
44
-
45
- Scenario: Adds a `config.ru`
46
- Given a fixture app "simple-app"
47
- Then the file "config.ru" should not exist
48
- Given a file named "config.rb" with:
49
- """
50
- activate :apps
51
- """
52
- And the Server is running at "simple-app"
53
- Then the file "config.ru" should exist
@@ -1,20 +0,0 @@
1
- Feature: Built app
2
-
3
- Scenario: Builds successfully
4
- Given a successfully built app at "simple-app"
5
- Then the file "config.ru" should exist
6
- And the file "build/index.html" should exist
7
- And the file "build/apps/test_app.rb" should not exist
8
-
9
- Scenario: Running built app
10
- Given a fixture app "simple-app"
11
- And app is running with config:
12
- """
13
- activate :apps
14
- """
15
- When I go to "/"
16
- Then I should see "<h1>Middleman</h1>"
17
- When I go to "/test-app"
18
- Then I should see "fail"
19
- When I go to "/test-app?test=1"
20
- Then I should see "pass"
@@ -1,18 +0,0 @@
1
- Feature: 404 error pages for Child apps
2
-
3
- Scenario: Custom 404 response from child app
4
- Given a fixture app "complex-app"
5
- And a file named "source/custom.html.erb" with:
6
- """
7
- <h2><%= 404 %> Custom Not Found!</h2>
8
- """
9
- And app is running with config:
10
- """
11
- activate :apps, not_found: "custom.html", namespace: :complex_app
12
- """
13
- When I go to "/child-app"
14
- Then I should see "hello"
15
- When I go to "/child-app/unknown"
16
- Then the status code should be "404"
17
- And I should see "<h2>404 Custom Not Found!</h2>"
18
-
@@ -1,66 +0,0 @@
1
- Feature: Real world JSON API example
2
-
3
- Scenario: Allows namespacing applications
4
- Given a fixture app "complex-app"
5
- And app is running with config:
6
- """
7
- activate :apps, namespace: "ComplexApp::SomeNamespace"
8
- """
9
- When I go to "/test-app?test=1"
10
- Then the status code should be "200"
11
- And I should see "pass"
12
-
13
- Scenario: Allows namespacing applications via underscored module path
14
- Given a fixture app "complex-app"
15
- And app is running with config:
16
- """
17
- activate :apps, namespace: "complex_app/some_namespace"
18
- """
19
- When I go to "/test-app?test=1"
20
- Then the status code should be "200"
21
- And I should see "pass"
22
-
23
- Scenario: Ignores modular apps that have no direct mapping
24
- Given a fixture app "complex-app"
25
- And app is running with config:
26
- """
27
- activate :apps, namespace: "other_namespacee"
28
- """
29
- When I go to "/test-app?test=1"
30
- Then the status code should be "404"
31
-
32
- Scenario: Allows specifying Application Name
33
- Given a fixture app "complex-app"
34
- And app is running with config:
35
- """
36
- activate :apps, namespace: :complex_app,
37
- map: { child_app: "/some-other-path/abcd" }
38
- """
39
- When I go to "/some-other-path/abcd"
40
- Then the status code should be "200"
41
- And I should see "hello"
42
-
43
- Scenario: Allows specifying URL path for application
44
- Given a fixture app "complex-app"
45
- And app is running with config:
46
- """
47
- activate :apps,
48
- namespace: 'complex_app/some_namespace',
49
- map: {
50
- test_app: 'test',
51
- awesome_api: {
52
- url: 'api',
53
- class: "OtherNamespace::AwesomeAPI"
54
- }
55
- }
56
- """
57
- When I go to "/test-app?test=1"
58
- Then the status code should be "404"
59
- When I go to "/test?test=1"
60
- Then the status code should be "200"
61
- And I should see "pass"
62
- When I go to "/awesome-api/ping"
63
- Then the status code should be "404"
64
- When I go to "/api/ping"
65
- Then the status code should be "200"
66
- And I should see "pong"
@@ -1,8 +0,0 @@
1
- Feature: 404 error pages with Middleman Preview Server
2
-
3
- Scenario: Fixed 404 response with Server
4
- Given a fixture app "simple-app"
5
- And the Server is running at "simple-app"
6
- When I go to "/unknown-app"
7
- Then the status code should be "404"
8
- And I should see "<h1>File Not Found</h1>"
@@ -1,23 +0,0 @@
1
- Feature: Verbose mode
2
-
3
- Scenario: Display list of child apps which were ignored
4
- Given a fixture app "complex-app"
5
- And I overwrite the file named "config.rb" with:
6
- """
7
- activate :apps, verbose: true
8
- """
9
- And I run `middleman build --verbose`
10
- And the aruba exit timeout is 2 seconds
11
- And I run `rackup -p 17283` in background
12
- Then the output should match:
13
- """
14
- Ignored child app:.*apps\/awesome_api\.rb
15
- """
16
- And the output should match:
17
- """
18
- Ignored child app:.*apps\/test_app\.rb
19
- """
20
- And the output should match:
21
- """
22
- Ignored child app:.*apps\/child_app\.rb
23
- """
@@ -1,11 +0,0 @@
1
- require 'sinatra'
2
-
3
- module OtherNamespace
4
- # Child app that tests specifying a specific namespace/class
5
- # for a single URL endpoint
6
- class AwesomeAPI < Sinatra::Base
7
- get '/ping' do
8
- 'pong'
9
- end
10
- end
11
- end
@@ -1 +0,0 @@
1
- <h1>Error!!</h1>
@@ -1 +0,0 @@
1
- activate :apps # , not_found: 'error.html'
@@ -1,8 +0,0 @@
1
- require 'sinatra'
2
-
3
- # Test application fixture
4
- class TestApp < Sinatra::Base
5
- get '/' do
6
- params[:test] ? 'pass' : 'fail'
7
- end
8
- end
@@ -1 +0,0 @@
1
- <h1>Error!!</h1>
@@ -1 +0,0 @@
1
- activate :apps # , not_found: 'error.html'