Class: Middleman::Cli::Build
- Inherits:
-
Thor
- Object
- Thor
- Middleman::Cli::Build
- Includes:
- Thor::Actions
- Defined in:
- middleman-core/lib/middleman-core/cli/build.rb
Overview
The CLI Build class
Class Method Summary (collapse)
- + (Boolean) exit_on_failure?
-
+ (Middleman::Application) shared_instance(verbose = false)
Middleman::Application singleton.
-
+ (Rack::Test::Session) shared_rack
Rack::Test::Session singleton.
-
+ (Middleman::Application) shared_server
Middleman::Application class singleton.
-
+ (Object) source_root
Set the root path to the Middleman::Application's root.
Instance Method Summary (collapse)
-
- (void) build
Core build Thor command.
-
- (String) render_to_file(resource)
Render a resource to a file.
Class Method Details
+ (Boolean) exit_on_failure?
56 57 58 |
# File 'middleman-core/lib/middleman-core/cli/build.rb', line 56 def exit_on_failure? true end |
+ (Middleman::Application) shared_instance(verbose = false)
Middleman::Application singleton
63 64 65 66 67 68 |
# File 'middleman-core/lib/middleman-core/cli/build.rb', line 63 def shared_instance(verbose=false) @_shared_instance ||= ::Middleman.server.inst do set :environment, :build set :logging, verbose end end |
+ (Rack::Test::Session) shared_rack
Rack::Test::Session singleton
80 81 82 83 84 85 86 87 |
# File 'middleman-core/lib/middleman-core/cli/build.rb', line 80 def shared_rack @_shared_rack ||= begin mock = ::Rack::MockSession.new(shared_server.to_rack_app) sess = ::Rack::Test::Session.new(mock) response = sess.get("__middleman__") sess end end |
+ (Middleman::Application) shared_server
Middleman::Application class singleton
73 74 75 |
# File 'middleman-core/lib/middleman-core/cli/build.rb', line 73 def shared_server @_shared_server ||= shared_instance.class end |
+ (Object) source_root
Set the root path to the Middleman::Application's root
90 91 92 |
# File 'middleman-core/lib/middleman-core/cli/build.rb', line 90 def source_root shared_instance.root end |
Instance Method Details
- (void) build
This method returns an undefined value.
Core build Thor command
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'middleman-core/lib/middleman-core/cli/build.rb', line 36 def build if !ENV["MM_ROOT"] raise Thor::Error, "Error: Could not find a Middleman project config, perhaps you are in the wrong folder?" end self.class.shared_instance(["verbose"] || false) self.class.shared_rack opts = {} opts[:glob] = ["glob"] if .has_key?("glob") opts[:clean] = ["clean"] if .has_key?("clean") action GlobAction.new(self, opts) self.class.shared_instance.run_hook :after_build, self end |
- (String) render_to_file(resource)
Render a resource to a file.
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'middleman-core/lib/middleman-core/cli/build.rb', line 102 def render_to_file(resource) build_dir = self.class.shared_instance.build_dir output_file = File.join(build_dir, resource.destination_path) begin response = self.class.shared_rack.get(URI.escape(resource.destination_path)) if response.status == 200 create_file(output_file, response.body, { :force => true }) else raise Thor::Error.new response.body end rescue => e say_status :error, output_file, :red raise Thor::Error.new "#{e}\n#{e.backtrace.join("\n")}" end output_file end |