middleman-apps 0.1.0 → 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.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.rubocop.yml +2 -1
- data/Gemfile +4 -0
- data/{LICENSE.txt → LICENSE} +0 -0
- data/README.md +166 -40
- data/features/e_asset_hash.feature +17 -0
- data/features/{directory_indexes.feature → e_directory_indexes.feature} +14 -16
- data/features/e_relative_assets.feature +17 -0
- data/features/f_code_reloading.feature +134 -0
- data/features/f_metadata.feature +25 -0
- data/features/{not_found_rack.feature → f_not_found.feature} +12 -22
- data/features/f_options.feature +39 -0
- data/features/step_definitions/capybara_steps.rb +18 -0
- data/features/step_definitions/mechanize_steps.rb +19 -0
- data/features/step_definitions/rack_app_steps.rb +4 -2
- data/features/support/aruba.rb +22 -0
- data/features/support/env.rb +0 -14
- data/features/support/helpers.rb +11 -0
- data/features/support/mechanize.rb +32 -0
- data/features/support/poltegeist.rb +35 -0
- data/features/v_activating.feature +74 -0
- data/features/v_building.feature +31 -0
- data/features/v_inheriting_from.feature +38 -0
- data/fixtures/asset_hash/apps/ignored_app.rb +10 -0
- data/fixtures/asset_hash/apps/test_app.rb +11 -0
- data/fixtures/asset_hash/config.rb +2 -0
- data/fixtures/asset_hash/source/error.html.erb +2 -0
- data/fixtures/{complex-app → asset_hash}/source/index.html.erb +0 -0
- data/fixtures/asset_hash/source/layouts/layout.erb +12 -0
- data/fixtures/asset_hash/source/layouts/page.erb +6 -0
- data/fixtures/asset_hash/source/stylesheets/style.css.scss.erb +5 -0
- data/fixtures/dir_index/apps/ignored_app.rb +10 -0
- data/fixtures/dir_index/apps/test_app.rb +10 -0
- data/fixtures/dir_index/config.rb +2 -0
- data/fixtures/{simple-app → dir_index}/source/index.html.erb +0 -0
- data/fixtures/mount_path/apps/test_app.rb +10 -0
- data/fixtures/mount_path/config.rb +1 -0
- data/fixtures/{complex-app/build/index.html → mount_path/source/index.html.erb} +0 -0
- data/fixtures/real_world/apps/awesome_api.rb +40 -0
- data/fixtures/{complex-app → real_world}/apps/child_app.rb +15 -2
- data/fixtures/{complex-app/apps/test_app.rb → real_world/apps/ignored_app.rb} +2 -2
- data/fixtures/real_world/apps/no_namespace.rb +8 -0
- data/fixtures/real_world/apps/test_app.rb +16 -0
- data/fixtures/real_world/config.rb +13 -0
- data/fixtures/real_world/source/apps.html.erb +14 -0
- data/fixtures/real_world/source/custom.html.erb +1 -0
- data/fixtures/{simple-app/build/index.html → real_world/source/index.html.erb} +0 -0
- data/fixtures/real_world/source/layouts/_partial.erb +1 -0
- data/fixtures/real_world/source/layouts/layout.erb +11 -0
- data/fixtures/real_world/source/layouts/page.erb +6 -0
- data/fixtures/real_world/source/layouts/test.html.markdown.erb +3 -0
- data/fixtures/relative_assets/apps/ignored_app.rb +10 -0
- data/fixtures/relative_assets/apps/test_app.rb +11 -0
- data/fixtures/relative_assets/config.rb +2 -0
- data/fixtures/relative_assets/source/error.html.erb +2 -0
- data/fixtures/relative_assets/source/index.html.erb +2 -0
- data/fixtures/relative_assets/source/layouts/layout.erb +12 -0
- data/fixtures/relative_assets/source/layouts/page.erb +6 -0
- data/fixtures/relative_assets/source/stylesheets/style.css.scss.erb +5 -0
- data/fixtures/simple/apps/ignored_app.rb +10 -0
- data/fixtures/simple/apps/test_app.rb +10 -0
- data/fixtures/simple/config.rb +1 -0
- data/fixtures/simple/source/index.html.erb +2 -0
- data/lib/middleman/apps.rb +26 -7
- data/lib/middleman/apps/base.rb +71 -15
- data/lib/middleman/apps/extension.rb +34 -158
- data/lib/middleman/apps/version.rb +2 -1
- data/lib/middleman/sitemap/app_collection.rb +225 -0
- data/lib/middleman/sitemap/app_resource.rb +61 -0
- metadata +77 -31
- data/features/activation.feature +0 -53
- data/features/build.feature +0 -20
- data/features/child_app.feature +0 -18
- data/features/complex_app.feature +0 -66
- data/features/not_found_server.feature +0 -8
- data/features/verbose.feature +0 -23
- data/fixtures/complex-app/apps/awesome_api.rb +0 -11
- data/fixtures/complex-app/build/error.html +0 -1
- data/fixtures/complex-app/config.rb +0 -1
- data/fixtures/simple-app/apps/test_app.rb +0 -8
- data/fixtures/simple-app/build/error.html +0 -1
- data/fixtures/simple-app/config.rb +0 -1
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
activate :apps, mount_path: '///a/b//c////d', namespace: 'MountPath'
|
File without changes
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'middleman/apps/base'
|
2
|
+
|
3
|
+
module OtherNamespace
|
4
|
+
# Child app that tests specifying a specific namespace/class
|
5
|
+
# for a single URL endpoint
|
6
|
+
class AwesomeAPI < Middleman::Apps::Base
|
7
|
+
post '/' do
|
8
|
+
status 201
|
9
|
+
'201 Created'
|
10
|
+
end
|
11
|
+
|
12
|
+
get '/ping' do
|
13
|
+
'pong'
|
14
|
+
end
|
15
|
+
|
16
|
+
add_routes_to_metadata
|
17
|
+
set_metadata :arbitrary, 'defined'
|
18
|
+
set_metadata :title, 'Awesome API'
|
19
|
+
set_metadata :description, <<-MARKDOWN
|
20
|
+
## Awesome API v3
|
21
|
+
|
22
|
+
A markdown formatted description for this `Awesome API` can be provided
|
23
|
+
here. It, also, serves as a simple documentation for anyone reading your
|
24
|
+
code later.
|
25
|
+
|
26
|
+
You can even set this method from outside this class like this:
|
27
|
+
|
28
|
+
description = File.read('long_docs_for_simple_api.md')
|
29
|
+
OtherNamespace::AwesomeAPI.set :page_description, description
|
30
|
+
|
31
|
+
Enough now!
|
32
|
+
MARKDOWN
|
33
|
+
|
34
|
+
get '/metadata' do
|
35
|
+
metadata.map do |key, val|
|
36
|
+
"#{key} => #{val}"
|
37
|
+
end.join("\n")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'middleman/apps/base'
|
2
2
|
|
3
|
-
module
|
3
|
+
module RealWorld
|
4
4
|
# Child app that inherits from Middleman::Apps::BaseApp (which in turn
|
5
5
|
# inherits from Sinatra::Base) for additional features, such as:
|
6
6
|
# - error pages will be same as your main middleman static app
|
@@ -9,7 +9,20 @@ module ComplexApp
|
|
9
9
|
#
|
10
10
|
class ChildApp < ::Middleman::Apps::Base
|
11
11
|
get '/' do
|
12
|
-
|
12
|
+
"hello #{named} world"
|
13
|
+
end
|
14
|
+
|
15
|
+
get '/test' do
|
16
|
+
middleman_layout :test
|
17
|
+
end
|
18
|
+
|
19
|
+
get '/page/:str' do
|
20
|
+
str = params[:str] || 'testing..'
|
21
|
+
middleman_layout :page, locals: { str: str }
|
22
|
+
end
|
23
|
+
|
24
|
+
def named
|
25
|
+
'my'
|
13
26
|
end
|
14
27
|
end
|
15
28
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'middleman/apps/base'
|
2
|
+
|
3
|
+
module RealWorld
|
4
|
+
# Child app that is used by option: namespace
|
5
|
+
class TestApp < Middleman::Apps::Base
|
6
|
+
get '/' do
|
7
|
+
params[:test] ? 'pass' : 'fail'
|
8
|
+
end
|
9
|
+
|
10
|
+
get '/metadata' do
|
11
|
+
metadata.map do |key, val|
|
12
|
+
"#{key} => #{val}"
|
13
|
+
end.join("\n")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<section class="articles index">
|
2
|
+
<h3 class="title">Available apps:</h3>
|
3
|
+
<ul>
|
4
|
+
<% apps_list.each_with_index do |app, i| %>
|
5
|
+
<article>
|
6
|
+
<h2 class="title">
|
7
|
+
<%= link_to app.title, app.url %>
|
8
|
+
</h2>
|
9
|
+
<p><%= app.description %></p>
|
10
|
+
</article>
|
11
|
+
<% end %>
|
12
|
+
</ul>
|
13
|
+
</section>
|
14
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
<h1><%= 404 %> Custom Not Found!</h1>
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
<h3>rendered partial</h3>
|
@@ -0,0 +1 @@
|
|
1
|
+
activate :apps, namespace: 'Simple'
|
data/lib/middleman/apps.rb
CHANGED
@@ -6,6 +6,7 @@ require 'middleman/apps/extension'
|
|
6
6
|
# Register this extension with the name of `apps`
|
7
7
|
Middleman::Extensions.register :apps, Middleman::Apps::Extension
|
8
8
|
|
9
|
+
# Namespace for the Middleman project
|
9
10
|
module Middleman
|
10
11
|
# Base namespace for `middleman-apps` extension.
|
11
12
|
#
|
@@ -23,12 +24,11 @@ module Middleman
|
|
23
24
|
|
24
25
|
# Middleman app instance for reference to configuration, etc.
|
25
26
|
#
|
26
|
-
# @return [Middleman::Application] an instance of
|
27
|
+
# @return [Middleman::Application] an instance of Middleman::Application
|
27
28
|
# using configuration in {MIDDLEMAN_OPTIONS}
|
28
29
|
#
|
29
30
|
def self.middleman_app
|
30
31
|
Middleman.setup_load_paths
|
31
|
-
|
32
32
|
::Middleman::Application.new do
|
33
33
|
MIDDLEMAN_OPTIONS.each do |key, val|
|
34
34
|
config[key] = val
|
@@ -43,10 +43,13 @@ module Middleman
|
|
43
43
|
#
|
44
44
|
# @see .rack_app `.rack_app` method which uses this internally
|
45
45
|
#
|
46
|
-
def self.
|
47
|
-
app
|
46
|
+
def self.with_app_list(app = nil, &block)
|
47
|
+
app ||= middleman_app
|
48
48
|
options = app.extensions[:apps].options.to_h
|
49
|
-
Middleman::Apps::Extension.new(app, options)
|
49
|
+
ex = Middleman::Apps::Extension.new(app, options)
|
50
|
+
app.sitemap.register_resource_list_manipulator(:child_apps, ex.collection)
|
51
|
+
app.sitemap.ensure_resource_list_updated!
|
52
|
+
block ? ex.collection.instance_eval(&block) : ex.collection
|
50
53
|
end
|
51
54
|
|
52
55
|
# Rack app comprising of the static (middleman) app with 404 pages, and
|
@@ -57,9 +60,25 @@ module Middleman
|
|
57
60
|
#
|
58
61
|
# @return [Rack::App] rack application configuration
|
59
62
|
def self.rack_app
|
60
|
-
|
61
|
-
|
63
|
+
with_app_list { mount_child_apps(middleman_static_app) }
|
64
|
+
end
|
65
|
+
|
66
|
+
# Find App Resource for the given class name
|
67
|
+
#
|
68
|
+
# @param [Class] klass - klass to search
|
69
|
+
# @return [Middleman::Sitemap::AppResource, nil] - found app resource if any
|
70
|
+
def self.find_app_resource_for(klass, app = nil)
|
71
|
+
Middleman::Sitemap::AppResource.find_by_klass(klass, app)
|
72
|
+
end
|
73
|
+
|
74
|
+
# Get content for the not found page as specified in options.
|
75
|
+
#
|
76
|
+
def self.not_found(rack_app = nil)
|
77
|
+
rack_app ||= middleman_app
|
78
|
+
path = with_app_list(rack_app) do
|
79
|
+
build_dir.join(find_resource(@options.not_found))
|
62
80
|
end
|
81
|
+
path.exist? ? path.read : "Not found\n"
|
63
82
|
end
|
64
83
|
end
|
65
84
|
end
|