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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 07e504c02695ba4f0387c2d974c49030b12a0655
4
- data.tar.gz: 46a2badf1b57e7572d6f71232999ce7783c8f50b
3
+ metadata.gz: 6a213786e26254de55227a6665424f7e292a309d
4
+ data.tar.gz: ee7f03b33678750f48025f9d1175066aaa89a9b1
5
5
  SHA512:
6
- metadata.gz: 110ab87281cb3a4109e9c3ef5b73d4db382a8622a7b34534b4b01ef31aaeab30af06e783bde2cccb727c9d043f32004eaf7d3e5227dfeafd00db1c293eff973e
7
- data.tar.gz: 5f8a7f7edc8b1785e3ff7da9ace36d4e731c7ec01319256adea95d71cdf4f200e49ee6c7cb0b6a5b8ef84d1798d8d6f01a95cc2e826dacb7483d978efe225a8d
6
+ metadata.gz: 39fc434b08df657f9e5784dd146e03808808ed51a068dbfa45433776a0b2c44aea81ceee060a1535f0847eddbe86df50dc1c299a95edcb27b7af7b46b9d3c231
7
+ data.tar.gz: 9581a50b7a073eff04dbf89fd8797ddb3d2324d2279a2bd6e65d6ec0f31482382e5abedbd80ac162afc8e2540dcbffdac059e423e6e28f11be67f984218f815b
data/.gitignore CHANGED
@@ -6,3 +6,6 @@
6
6
 
7
7
  /tmp
8
8
  /doc
9
+ /.yardoc
10
+ *.gem
11
+ config.ru
@@ -1,7 +1,8 @@
1
1
  AllCops:
2
2
  Exclude:
3
3
  - 'lib/middleman/apps/rack_contrib.rb'
4
- - 'tmp/aruba'
4
+ - 'tmp/aruba/**/*'
5
+ - 'features/**/*'
5
6
 
6
7
  Metrics/ClassLength:
7
8
  Exclude:
data/Gemfile CHANGED
@@ -6,6 +6,7 @@ source 'https://rubygems.org'
6
6
  gemspec
7
7
 
8
8
  group :development do
9
+ gem 'pry'
9
10
  gem 'rake'
10
11
  gem 'rdoc'
11
12
  gem 'yard'
@@ -14,6 +15,9 @@ end
14
15
  group :test do
15
16
  gem 'aruba'
16
17
  gem 'capybara'
18
+ gem 'capybara-mechanize'
17
19
  gem 'cucumber'
20
+ gem 'poltergeist'
21
+ gem 'redcarpet', '~> 3.3', '>= 3.3.3'
18
22
  gem 'rspec'
19
23
  end
File without changes
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- ## Middleman Apps
1
+ ## Middleman Apps [![Build](https://api.travis-ci.org/nikhgupta/middleman-apps.svg?branch=master)](https://travis-ci.org/nikhgupta/middleman-apps)
2
2
 
3
3
  `middleman-apps` is an extension for the [Middleman] static site
4
4
  generator that allows you to run truly dynamic pages within your static
@@ -12,21 +12,26 @@ You can create dynamic pages using this extension. Maybe you want to:
12
12
  - Display a dynamic Gallery of your most recent timeline from Flickr?
13
13
  - ... suggest one? ...
14
14
 
15
- The best way to get started with this extension is to have a look at the
16
- various `features` in the test suite. There is a test for each feature
17
- that exists for extension, such as:
18
-
19
- - Mount Rack apps by, simply, placing them in `MM_ROOT/apps` directory.
20
- - Allow running child apps in-tandem with the static (built) MM app, and
21
- wrap them both in a single `Rack::App`, which can be run with e.g.
22
- `rackup`.
23
- - Use a specific `404` error page that is common across your static
24
- website, and child apps mounted using this extension.
25
- - Discovery of mountable child apps and automatic mounting.
26
- - Optionally, specify a URL where a child app should be mounted.
27
- - Optionally, specify a Class name or namespace for the child app.
28
- - Optionally, inherit from `Middleman::Apps::BaseApp` for helper methods
29
- and added goodies for your apps.
15
+ ## Installation
16
+
17
+ If you're just getting started, install the `middleman` gem and generate
18
+ a new project:
19
+
20
+ ```
21
+ gem install middleman
22
+ middleman init MY_PROJECT
23
+ ```
24
+
25
+ If you already have a Middleman project: Add `gem "middleman-apps"`
26
+ to your `Gemfile` and run `bundle install`.
27
+
28
+ ## Getting Started
29
+
30
+ To get started with this extension, you only need to place a rack app
31
+ inside `MM_ROOT/apps` directory. Now, run `middleman build` or
32
+ `middleman server`, and your rack app will be mounted for you.
33
+
34
+ The app should be visible in `/__middleman/sitemap`, as well.
30
35
 
31
36
  ### Example
32
37
 
@@ -55,21 +60,51 @@ Run/Build your Middleman site now, and visit:
55
60
  `/base64-api/encode/somestring`. Voila! It just works!
56
61
 
57
62
  A `config.ru` is, also, generated for you, so that you can keep
58
- using these dynamic pages/endpoints using `rackup`. Try running
59
- `rackup`, and visiting the above endpoint on that server instance.
63
+ using these child apps/endpoints in production mode, e.g. via `puma`,
64
+ `rackup`, etc.. Try running `rackup`, and visiting the above endpoint on
65
+ that server.
60
66
 
61
- ## Installation
67
+ ## Features
62
68
 
63
- If you're just getting started, install the `middleman` gem and generate
64
- a new project:
69
+ Consider a real world example, where you have a Middleman website
70
+ running at `/`. Now, everything is static at this point. Lets, provide
71
+ a page on this website, which redirects the user to a random blog entry
72
+ from the last year. Lets assume this isn't possible without Javascript,
73
+ or maybe you need to do some server-side processing before you redirect.
65
74
 
66
- ```
67
- gem install middleman
68
- middleman init MY_PROJECT
69
- ```
75
+ Well, we can write down a succint Sinatra application that queries
76
+ Middleman's sitemap in the realtime, and redirect to a random article
77
+ from there. Let's call this a `child app`.
70
78
 
71
- If you already have a Middleman project: Add `gem "middleman-apps"`
72
- to your `Gemfile` and run `bundle install`.
79
+ Using this extension, you can place this `child app` inside your
80
+ Middleman directory, and have it mounted at a specific path, and add
81
+ other niceties, and so on.
82
+
83
+ - Creates an `umbrella` rack-app that mounts Middleman to `/` and all
84
+ other child apps inside itseslf. You can run this umbrella application
85
+ in development mode using `middleman server`.
86
+
87
+ - A `config.ru` is generated for you, so that you can run this
88
+ `umbrella` application in production using `rackup`, `puma`, etc. What
89
+ you see in development is what you get in production (nearly).
90
+
91
+ - Use a specific `404` error page that is used across `middleman`
92
+ application and `child apps` in production mode.
93
+
94
+ - Automatic reloading of code for child apps in development mode.
95
+
96
+ - Specify `url` where a given `child-app` should be mounted.
97
+
98
+ - Use Middleman layouts in the HTML rendered by child apps. Requires
99
+ child apps to be inherited from `Middleman::Apps::Base`, which in turn
100
+ inherits from `Sinatra::Base`.
101
+
102
+ Inheriting from this class, also, provides you with several other
103
+ goodies, such as specifying title and description for your child apps,
104
+ so that they can be listed on some page with some overview of what
105
+ they do. It is recommended to inherit from this class, when possible.
106
+
107
+ - Works well with `DirectoryIndexes`, and `AssetHash` extensions.
73
108
 
74
109
  ## Configuration
75
110
 
@@ -78,18 +113,11 @@ activate :apps,
78
113
  map: {}, # Mappings for custom URL and Class for child apps
79
114
  verbose: false, # Display warnings if any when building main app
80
115
  not_found: "404.html", # Render this page for 404 errors, if it exists
81
- namespace: nil # By default, use a namespace for finding Class
82
- # of a child app
116
+ namespace: nil, # Use a namespace for Class of a child app
117
+ mount_path: '/', # Prefix all child apps URLs with this path
118
+ app_dir: 'apps' # Child apps are placed in this directory.
83
119
  ```
84
120
 
85
- A `config.ru` will be generated for you (if one does not exist already),
86
- when you preview/build your MM site. Your child apps will be mounted in
87
- both development (preview) mode (e.g. via `middleman server`) as well in
88
- production (build) mode of MM (e.g. running the built app using `puma`
89
- or `rackup`).
90
-
91
- ## Options
92
-
93
121
  ### `not_found: '404.html'`
94
122
 
95
123
  This option defines a custom HTML page to use for 404 errors. By
@@ -100,11 +128,14 @@ A warning is generated in `verbose` mode, if this file does not exist!
100
128
  Set this option to `false`, if you prefer not to use a 404 page and
101
129
  would rather stick with default 404 response from Rack.
102
130
 
131
+ At the moment, this page can not be shown in `development` mode, but
132
+ will be used for missing URIs across the `umbrella` application in
133
+ `production`.
134
+
103
135
  ### `verbose: false`
104
136
 
105
137
  If true, display warnings such as non-existent 404 error page, and any
106
- child apps that were ignored when starting server in
107
- development/production mode.
138
+ child apps that were ignored when starting server or building it.
108
139
 
109
140
  ### `namespace: nil`
110
141
 
@@ -114,7 +145,7 @@ below for better clarification.
114
145
  ### `map: {}`
115
146
 
116
147
  This option can be used to specify a custom URL endpoint for a specific
117
- child app, or different class name for your child app if different than
148
+ child app, or class name for your child app if different than
118
149
  what is guessed (`str.classify.constantize`).
119
150
 
120
151
  ```ruby
@@ -143,6 +174,100 @@ With the above configuration in place, here is what happens:
143
174
  `MM_ROOT/apps/other_mini_project.rb`, it will be mounted at:
144
175
  `/other-mini-project` endpoint.
145
176
 
177
+ ### `mount_path: /a/b/c/d`:
178
+
179
+ Prefix URL for child apps with the given string, such that a child app
180
+ that was to be mounted on `/child-app`, will now be mounted at:
181
+ `/a/b/c/d/child-app`.
182
+
183
+ ### `app_dir: apps`:
184
+
185
+ Customize the name of the directory used to host all child apps.
186
+
187
+ ## Middleman Layouts
188
+
189
+ Child apps can use Middleman layouts, if required. This is useful to
190
+ keep a seamless appearance across the `umbrella` application.
191
+
192
+ To use Middleman layouts, inherit your child app from
193
+ `Middleman::Apps::Base` and call `middleman_layout` with appropriate
194
+ layout name, like this:
195
+
196
+ require 'middleman/apps/base'
197
+
198
+ class TestApp < Middleman::Apps::Base
199
+ get '/' do
200
+ middleman_layout :page, locals: { var: value }
201
+ end
202
+ end
203
+
204
+ The above call to `middleman layout` will try to render
205
+ `source/layouts/page.erb` layout from Middleman and pass it specified
206
+ options or locals.
207
+
208
+ ## Listing child apps on a Middleman Page
209
+
210
+ # in: source/apps.html.erb
211
+
212
+ <section class="child-apps list">
213
+ <h3 class="title">Available apps:</h3>
214
+ <ul>
215
+ <% apps_list.each_with_index do |app, i| %>
216
+ <article>
217
+ <h2 class="title"><%= link_to app.title, app.url %></h2>
218
+ <p><%= app.html_description %></p>
219
+ </article>
220
+ <% end %>
221
+ </ul>
222
+ </section>
223
+
224
+ - `title`, `url`, and `routes` for the application are added on their
225
+ own.
226
+ - To overwrite `title`, or provide `description`, or any other arbitrary
227
+ metadata for your child app, you can make a call to `set_metadata(key,
228
+ val)` in your child app (must inherit from `Middleman::Apps::Base`).
229
+
230
+ - Markdown should be provided to `description`, which will be used to
231
+ populate `html_description`.
232
+
233
+ - Call `metadata` in your child app to have a peek at all the variables
234
+ that can be accessed this way.
235
+
236
+ For example:
237
+
238
+ require 'middleman/apps/base'
239
+
240
+ class SomeApp < ::Middleman::Apps::Base
241
+ get '/' do
242
+ 'hello'
243
+ end
244
+
245
+ post '/' do
246
+ 'done'
247
+ end
248
+
249
+ add_routes_to_metadata :get # only `get` routes in metadata
250
+ set_metadata :title, 'Awesome Application'
251
+ set_metadata :description, <<-MARKDOWN
252
+ # Description for this Child application
253
+
254
+ This will be added as a metadata property for this child app.
255
+ MARKDOWN
256
+ end
257
+
258
+ ## Notes/Gotchas
259
+
260
+ - To setup `routes` metadata, call `add_routes_to_metadata` at the end
261
+ of your child app (after, actually, defining your routes).
262
+
263
+ - 404 error page is not shown in `development` mode, i.e. when running
264
+ `middleman server`. A default `File Not Found` message is shown in
265
+ this case, by Middleman.
266
+
267
+ - When `relative_assets` is activated, 404 errors on
268
+ `/deeper/pages/in/your/website` will have wrong assets, and layout for
269
+ 404 pages may be inconsistent with the rest of the site in this case.
270
+
146
271
  ## Community
147
272
 
148
273
  The official community forum is available at: http://forum.middlemanapp.com
@@ -183,3 +308,4 @@ Copyright (c) 2018 Nikhil Gupta. MIT Licensed, see [LICENSE] for details.
183
308
 
184
309
  [middleman]: http://middlemanapp.com
185
310
  [LICENSE]: https://github.com/nikhgupta/middleman-apps/blob/master/LICENSE.txt
311
+ [Simple]: https://github.com/nikhgupta/middleman-apps/tree/master/fixtures/simple
@@ -0,0 +1,17 @@
1
+ Feature: Compatibility with other Extensions: AssetHash
2
+
3
+ @production @javascript
4
+ Scenario: Custom error page with AssetHash
5
+ Given successfully built app is running at "asset_hash"
6
+ When I go to "/unknown-app"
7
+ Then the status code should be "404"
8
+ And I should see text "404 - Not Found!"
9
+ And I should not see text "Error"
10
+
11
+ @production @javascript
12
+ Scenario: Custom error page with AssetHash
13
+ Given successfully built app is running at "asset_hash"
14
+ When I go to "/unknown-app/some/deep/nested/url"
15
+ Then the status code should be "404"
16
+ And I should see text "404 - Not Found!"
17
+ And I should not see text "Error"
@@ -1,18 +1,14 @@
1
- Feature: Compatibility with other Extensions
1
+ Feature: Compatibility with other Extensions: DirectoryIndex
2
2
 
3
3
  # Use custom error page for `middleman-apps`:
4
4
  # with Directory Indexes on - using `find_resource_by_path`
5
5
  Scenario: Custom error page with Directory Indexes
6
- Given a fixture app "simple-app"
7
- And a file named "source/custom.html.erb" with:
6
+ Given a fixture app "dir_index"
7
+ And a file named "source/error.html.erb" with:
8
8
  """
9
9
  <h2><%= 404 %> Custom Not Found!</h2>
10
10
  """
11
- And app is running with config:
12
- """
13
- activate :directory_indexes
14
- activate :apps, not_found: "custom.html"
15
- """
11
+ And app is running
16
12
  When I go to "/unknown-app"
17
13
  Then the status code should be "404"
18
14
  And I should see "<h2>404 Custom Not Found!</h2>"
@@ -20,16 +16,17 @@ Feature: Compatibility with other Extensions
20
16
  # Use custom error page for `middleman-apps`:
21
17
  # with Directory Indexes on - using `find_resource_by_destination_path`
22
18
  Scenario: Custom error page with Directory Indexes
23
- Given a fixture app "simple-app"
24
- And a file named "source/custom.html.erb" with:
19
+ Given a fixture app "dir_index"
20
+ And a file named "source/error.html.erb" with:
25
21
  """
26
22
  <h2><%= 404 %> Custom Not Found!</h2>
27
23
  """
28
- And app is running with config:
24
+ And I overwrite the file named "config.rb" with:
29
25
  """
30
26
  activate :directory_indexes
31
- activate :apps, not_found: "custom/index.html"
27
+ activate :apps, not_found: "error/index.html"
32
28
  """
29
+ And app is running
33
30
  When I go to "/unknown-app"
34
31
  Then the status code should be "404"
35
32
  And I should see "<h2>404 Custom Not Found!</h2>"
@@ -37,16 +34,17 @@ Feature: Compatibility with other Extensions
37
34
  # Use custom error page for `middleman-apps`:
38
35
  # with Directory Indexes on - using `find_resource_by_page_id`
39
36
  Scenario: Custom error page with Directory Indexes
40
- Given a fixture app "simple-app"
41
- And a file named "source/custom.html.erb" with:
37
+ Given a fixture app "dir_index"
38
+ And a file named "source/error.html.erb" with:
42
39
  """
43
40
  <h2><%= 404 %> Custom Not Found!</h2>
44
41
  """
45
- And app is running with config:
42
+ And I overwrite the file named "config.rb" with:
46
43
  """
47
44
  activate :directory_indexes
48
- activate :apps, not_found: "custom"
45
+ activate :apps, not_found: "error"
49
46
  """
47
+ And app is running
50
48
  When I go to "/unknown-app"
51
49
  Then the status code should be "404"
52
50
  And I should see "<h2>404 Custom Not Found!</h2>"
@@ -0,0 +1,17 @@
1
+ Feature: Compatibility with other Extensions: RelativeAssets
2
+
3
+ @production @javascript
4
+ Scenario: Custom error page with RelativeAssets
5
+ Given successfully built app is running at "relative_assets"
6
+ When I go to "/unknown-app"
7
+ Then the status code should be "404"
8
+ And I should see text "404 - Not Found!"
9
+ And I should not see text "Error"
10
+
11
+ @production @javascript @wip
12
+ Scenario: Custom error page with RelativeAssets
13
+ Given successfully built app is running at "relative_assets"
14
+ When I go to "/unknown-app/some/deep/nested/url"
15
+ Then the status code should be "404"
16
+ And I should see text "404 - Not Found!"
17
+ And I should not see text "Error"
@@ -0,0 +1,134 @@
1
+ Feature: Code reloading for child apps
2
+
3
+ @mechanize @development
4
+ Scenario: Allows reloading in development server
5
+ Given a fixture app "real_world"
6
+ And server is running in background
7
+ When I go to "/child-app" on local server
8
+ Then I should see "hello my world"
9
+ When I overwrite the file named "apps/child_app.rb" with:
10
+ """
11
+ require 'middleman/apps/base'
12
+ class RealWorld::ChildApp < ::Middleman::Apps::Base
13
+ get '/' do
14
+ "reloaded #{named} world"
15
+ end
16
+ def named; 'other'; end
17
+ end
18
+ """
19
+ And I go to "/child-app" on local server
20
+ Then I should see "reloaded other world"
21
+
22
+ @mechanize @development
23
+ Scenario: Allows reloading for apps without any namespace
24
+ Given a fixture app "real_world"
25
+ And server is running in background
26
+ When I go to "/no-name" on local server
27
+ Then I should see "pass"
28
+ When I overwrite the file named "apps/no_namespace.rb" with:
29
+ """
30
+ require 'middleman/apps/base'
31
+ class NoNamespaceApp < ::Middleman::Apps::Base
32
+ get '/' do
33
+ "reloaded"
34
+ end
35
+ end
36
+ """
37
+ And I go to "/no-name" on local server
38
+ Then I should see "reloaded"
39
+
40
+ @mechanize @development
41
+ Scenario: Throws 404 when child app is suddenly ignored
42
+ Given a fixture app "real_world"
43
+ And server is running in background
44
+ When I overwrite the file named "apps/child_app.rb" with:
45
+ """
46
+ require 'middleman/apps/base'
47
+ class ChildApp < ::Middleman::Apps::Base
48
+ get '/' do
49
+ "reloaded #{named} world"
50
+ end
51
+ def named; 'other'; end
52
+ end
53
+ """
54
+ And I go to "/child-app" on local server
55
+ Then the status code should be "404"
56
+
57
+ @mechanize @production
58
+ Scenario: Do not allow reloading of apps in production
59
+ Given a fixture app "real_world"
60
+ And server is running in background
61
+ When I go to "/child-app" on local server
62
+ Then I should see "hello my world"
63
+ When I overwrite the file named "apps/child_app.rb" with:
64
+ """
65
+ require 'middleman/apps/base'
66
+ class RealWorld::ChildApp < ::Middleman::Apps::Base
67
+ get '/' do
68
+ 'hello world\n' * n
69
+ end
70
+ def n; 2; end
71
+ end
72
+ """
73
+ And I go to "/child-app" on local server
74
+ Then I should see "hello my world"
75
+
76
+ @mechanize @development
77
+ Scenario: New child apps are loaded automatically
78
+ Given a fixture app "real_world"
79
+ And server is running in background
80
+ When I go to "/unknown-app" on local server
81
+ Then the status code should be "404"
82
+ And I should see "File Not Found"
83
+ When I write to "apps/unknown_app.rb" with:
84
+ """
85
+ require 'middleman/apps/base'
86
+ class RealWorld::UnknownApp < ::Middleman::Apps::Base
87
+ get '/' do
88
+ "I am now!"
89
+ end
90
+ end
91
+ """
92
+ And I go to "/unknown-app" on local server
93
+ Then I should see "I am now!"
94
+
95
+ @mechanize @production
96
+ Scenario: New child apps are NOT loaded automatically
97
+ Given a fixture app "real_world"
98
+ And server is running in background
99
+ When I go to "/unknown-app" on local server
100
+ Then the status code should be "404"
101
+ And I should see "Not Found"
102
+ When I write to "apps/unknown_app.rb" with:
103
+ """
104
+ require 'middleman/apps/base'
105
+ class RealWorld::UnknownApp < ::Middleman::Apps::Base
106
+ get '/' do
107
+ "I am now!"
108
+ end
109
+ end
110
+ """
111
+ And I go to "/unknown-app" on local server
112
+ Then the status code should be "404"
113
+ And I should see "Not Found"
114
+
115
+ @mechanize @development
116
+ Scenario: Removing child apps removes them from server
117
+ Given a fixture app "real_world"
118
+ And server is running in background
119
+ When I go to "/child-app" on local server
120
+ Then I should see "hello my world"
121
+ When I remove the file named "apps/child_app.rb"
122
+ And I go to "/child-app" on local server
123
+ Then the status code should be "404"
124
+ And I should see "File Not Found"
125
+
126
+ @mechanize @production
127
+ Scenario: Removing child apps does NOT remove them from server
128
+ Given a fixture app "real_world"
129
+ And server is running in background
130
+ When I go to "/child-app" on local server
131
+ Then I should see "hello my world"
132
+ When I remove the file named "apps/child_app.rb"
133
+ And I go to "/child-app" on local server
134
+ Then I should see "hello my world"