Module: Middleman::Apps
- Defined in:
- lib/middleman/apps.rb,
lib/middleman/apps/base.rb,
lib/middleman/apps/version.rb,
lib/middleman/apps/extension.rb
Overview
Base namespace for ‘middleman-apps` extension.
Defined Under Namespace
Constant Summary collapse
- ENVIRONMENT =
Environment in which MM should be run
(ENV['MM_ENV'] || ENV['RACK_ENV'] || 'development').to_sym
- MIDDLEMAN_OPTIONS =
Middleman options that would be passed to create a reference instance.
{ mode: :config, watcher_disable: true, exit_before_ready: true, environment: ENVIRONMENT }.freeze
- VERSION =
current version for this gem
'0.2.0'.freeze
Class Method Summary collapse
-
.find_app_resource_for(klass, app = nil) ⇒ Middleman::Sitemap::AppResource?
Find App Resource for the given class name.
-
.middleman_app ⇒ Middleman::Application
Middleman app instance for reference to configuration, etc.
-
.not_found(rack_app = nil) ⇒ Object
Get content for the not found page as specified in options.
-
.rack_app ⇒ Rack::App
Rack app comprising of the static (middleman) app with 404 pages, and child apps properly mounted.
-
.with_app_list(app = nil, &block) ⇒ Any
Evaluate some code within the context of this extension.
Class Method Details
.find_app_resource_for(klass, app = nil) ⇒ Middleman::Sitemap::AppResource?
Find App Resource for the given class name
70 71 72 |
# File 'lib/middleman/apps.rb', line 70 def self.find_app_resource_for(klass, app = nil) Middleman::Sitemap::AppResource.find_by_klass(klass, app) end |
.middleman_app ⇒ Middleman::Application
Middleman app instance for reference to configuration, etc.
30 31 32 33 34 35 36 37 |
# File 'lib/middleman/apps.rb', line 30 def self.middleman_app Middleman.setup_load_paths ::Middleman::Application.new do MIDDLEMAN_OPTIONS.each do |key, val| config[key] = val end end end |
.not_found(rack_app = nil) ⇒ Object
Get content for the not found page as specified in options.
76 77 78 79 80 81 82 |
# File 'lib/middleman/apps.rb', line 76 def self.not_found(rack_app = nil) rack_app ||= middleman_app path = with_app_list(rack_app) do build_dir.join(find_resource(@options.not_found)) end path.exist? ? path.read : "Not found\n" end |
.rack_app ⇒ Rack::App
Rack app comprising of the static (middleman) app with 404 pages, and child apps properly mounted.
This method can be used directly to create a Rack app. Refer to the generated ‘config.ru` for an example.
62 63 64 |
# File 'lib/middleman/apps.rb', line 62 def self.rack_app with_app_list { mount_child_apps(middleman_static_app) } end |
.with_app_list(app = nil, &block) ⇒ Any
Evaluate some code within the context of this extension.
46 47 48 49 50 51 52 53 |
# File 'lib/middleman/apps.rb', line 46 def self.with_app_list(app = nil, &block) app ||= middleman_app = app.extensions[:apps]..to_h ex = Middleman::Apps::Extension.new(app, ) app.sitemap.register_resource_list_manipulator(:child_apps, ex.collection) app.sitemap.ensure_resource_list_updated! block ? ex.collection.instance_eval(&block) : ex.collection end |