Module: Padrino
- Defined in:
- lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/version.rb,
lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core.rb,
lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/tasks.rb,
lib/vendored-middleman-deps/padrino-helpers-0.11.2/lib/padrino-helpers.rb,
lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/caller.rb,
lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/loader.rb,
lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/logger.rb,
lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/module.rb,
lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/router.rb,
lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/server.rb,
lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/command.rb,
lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/mounter.rb,
lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/cli/base.rb,
lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/reloader.rb,
lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/application.rb,
lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/cli/adapter.rb,
lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/support_lite.rb,
lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/application/flash.rb,
lib/vendored-middleman-deps/padrino-helpers-0.11.2/lib/padrino-helpers/tag_helpers.rb,
lib/vendored-middleman-deps/padrino-helpers-0.11.2/lib/padrino-helpers/form_helpers.rb,
lib/vendored-middleman-deps/padrino-helpers-0.11.2/lib/padrino-helpers/format_helpers.rb,
lib/vendored-middleman-deps/padrino-helpers-0.11.2/lib/padrino-helpers/number_helpers.rb,
lib/vendored-middleman-deps/padrino-helpers-0.11.2/lib/padrino-helpers/output_helpers.rb,
lib/vendored-middleman-deps/padrino-helpers-0.11.2/lib/padrino-helpers/render_helpers.rb,
lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/application/rendering.rb,
lib/vendored-middleman-deps/padrino-helpers-0.11.2/lib/padrino-helpers/asset_tag_helpers.rb,
lib/vendored-middleman-deps/padrino-helpers-0.11.2/lib/padrino-helpers/breadcrumb_helpers.rb,
lib/vendored-middleman-deps/padrino-helpers-0.11.2/lib/padrino-helpers/translation_helpers.rb,
lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/application/showexceptions.rb,
lib/vendored-middleman-deps/padrino-helpers-0.11.2/lib/padrino-helpers/output_helpers/erb_handler.rb,
lib/vendored-middleman-deps/padrino-helpers-0.11.2/lib/padrino-helpers/output_helpers/haml_handler.rb,
lib/vendored-middleman-deps/padrino-helpers-0.11.2/lib/padrino-helpers/output_helpers/slim_handler.rb,
lib/vendored-middleman-deps/padrino-helpers-0.11.2/lib/padrino-helpers/output_helpers/abstract_handler.rb,
lib/vendored-middleman-deps/padrino-helpers-0.11.2/lib/padrino-helpers/form_builder/abstract_form_builder.rb,
lib/vendored-middleman-deps/padrino-helpers-0.11.2/lib/padrino-helpers/form_builder/standard_form_builder.rb,
lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/application/routing.rb
Overview
Make slim works with sinatra/padrino
Defined Under Namespace
Modules: Cli, Flash, Helpers, Module, Reloader, Rendering, Routing, Tasks Classes: Application, ApplicationLoadError, ApplicationSetupError, Filter, Logger, Mounter, Router, Server, ShowExceptions, Utils
Constant Summary collapse
- PADRINO_IGNORE_CALLERS =
List of callers in a Padrino application that should be ignored as part of a stack trace.
[ %r{lib/padrino-.*$}, # all padrino code %r{/padrino-.*/(lib|bin)}, # all padrino code %r{/bin/padrino$}, # all padrino code %r{/sinatra(/(base|main|showexceptions))?\.rb$}, # all sinatra code %r{lib/tilt.*\.rb$}, # all tilt code %r{lib/rack.*\.rb$}, # all rack code %r{lib/mongrel.*\.rb$}, # all mongrel code %r{lib/shotgun.*\.rb$}, # all shotgun lib %r{bin/shotgun$}, # shotgun binary %r{\(.*\)}, # generated code %r{shoulda/context\.rb$}, # shoulda hacks %r{mocha/integration}, # mocha hacks %r{test/unit}, # test unit hacks %r{rake_test_loader\.rb}, # rake hacks %r{custom_require\.rb$}, # rubygems require hacks %r{active_support}, # active_support require hacks %r{/thor} # thor require hacks ]
- VERSION =
The version constant for the current version of Padrino.
'0.11.2'
Class Attribute Summary collapse
-
.mounted_root(*args) ⇒ String
The root to the mounted apps base directory.
Class Method Summary collapse
-
.after_load { ... } ⇒ Array<Proc>
Hooks to be called after a load/reload.
-
.application ⇒ Padrino::Router
The resulting rack builder mapping each ‘mounted’ application.
-
.apps_configuration ⇒ Object
Returns project-wide configuration settings defined in Padrino.configure_apps block.
-
.before_load { ... } ⇒ Array<Proc>
Hooks to be called before a load/reload.
-
.bin(*args) ⇒ Boolean
This method return the correct location of padrino bin or exec it using Kernel#system with the given args.
-
.called_from ⇒ Object
This adds the ablity to instantiate Padrino.load! after Application definition.
-
.clear! ⇒ NilClass
Clear the padrino env.
-
.clear_middleware! ⇒ Array
Clears all previously configured middlewares.
-
.configure_apps { ... } ⇒ Object
Configure Global Project Settings for mounted apps.
-
.dependency_paths ⇒ Array<String>
Returns default list of path globs to load as dependencies Appends custom dependency patterns to the be loaded for Padrino.
-
.env ⇒ Symbol
Helper method that return PADRINO_ENV.
-
.gem(name, main_module) ⇒ Object
Registers a gem with padrino.
-
.gems ⇒ Object
Returns all currently known padrino gems.
-
.insert_mounted_app(mounter) ⇒ Object
Inserts a Mounter object into the mounted applications (avoids duplicates).
-
.load! ⇒ Boolean
Requires necessary dependencies as well as application files from root lib and models.
-
.load_paths ⇒ Array<String>
The used $LOAD_PATHS from Padrino.
-
.loaded? ⇒ Boolean
Determines whether Padrino was loaded with Padrino.load!.
- .logger ⇒ Padrino::Logger
-
.logger=(value) ⇒ Object
Set the padrino logger.
-
.middleware ⇒ Array<Array<Class, Array, Proc>>
A Rack::Builder object that allows to add middlewares in front of all Padrino applications.
-
.modules ⇒ Object
All loaded Padrino modules.
-
.mount(name, options = {}) ⇒ Object
Mounts a new sub-application onto Padrino project.
-
.mounted_apps ⇒ Array
The mounted padrino applications (MountedApp objects).
-
.reload! ⇒ Object
Method for reloading required applications and their files.
-
.require_dependencies(*paths) ⇒ Object
Attempts to require all dependency libs that we need.
-
.root(*args) ⇒ String
Helper method for file references.
-
.ruby_command ⇒ String
Return the path to the ruby interpreter taking into account multiple installations and windows extensions.
-
.run!(options = {}) ⇒ Object
Runs the Padrino apps as a self-hosted server using: thin, mongrel, or webrick in that order.
-
.set_encoding ⇒ NilClass
Set
Encoding.default_internal
andEncoding.default_external
toEncoding::UFT_8
. -
.set_load_paths(*paths) ⇒ Object
Concat to $LOAD_PATH the given paths.
-
.use(m, *args) { ... } ⇒ Object
Convenience method for adding a Middleware to the whole padrino app.
-
.version ⇒ String
The current Padrino version.
Instance Method Summary collapse
-
#RUBY_IGNORE_CALLERS ⇒ Object
Add rubinius (and hopefully other VM implementations) ignore patterns …
Class Attribute Details
Class Method Details
.after_load { ... } ⇒ Array<Proc>
Hooks to be called after a load/reload.
37 38 39 40 41 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/loader.rb', line 37 def after_load(&block) @_after_load ||= [] @_after_load << block if block_given? @_after_load end |
.application ⇒ Padrino::Router
The resulting rack builder mapping each ‘mounted’ application.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core.rb', line 65 def application raise ApplicationLoadError, "At least one app must be mounted!" unless Padrino.mounted_apps && Padrino.mounted_apps.any? router = Padrino::Router.new Padrino.mounted_apps.each { |app| app.map_onto(router) } if middleware.present? builder = Rack::Builder.new middleware.each { |c,a,b| builder.use(c, *a, &b) } builder.run(router) builder.to_app else router end end |
.apps_configuration ⇒ Object
Returns project-wide configuration settings defined in configure_apps block.
108 109 110 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core.rb', line 108 def apps_configuration @_global_configuration end |
.before_load { ... } ⇒ Array<Proc>
Hooks to be called before a load/reload.
17 18 19 20 21 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/loader.rb', line 17 def before_load(&block) @_before_load ||= [] @_before_load << block if block_given? @_before_load end |
.bin(*args) ⇒ Boolean
This method return the correct location of padrino bin or exec it using Kernel#system with the given args
16 17 18 19 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/command.rb', line 16 def self.bin(*args) @_padrino_bin ||= [self.ruby_command, File.("../../../bin/padrino", __FILE__)] args.empty? ? @_padrino_bin : system(args.unshift(@_padrino_bin).join(" ")) end |
.called_from ⇒ Object
This adds the ablity to instantiate load! after Application definition.
111 112 113 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/loader.rb', line 111 def called_from @_called_from || first_caller end |
.clear! ⇒ NilClass
Clear the padrino env.
85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/loader.rb', line 85 def clear! Padrino.clear_middleware! Padrino.mounted_apps.clear @_load_paths = nil @_dependency_paths = nil @_global_configuration = nil Padrino.before_load.clear Padrino.after_load.clear Padrino::Reloader.clear! Thread.current[:padrino_loaded] = nil end |
.clear_middleware! ⇒ Array
Clears all previously configured middlewares.
150 151 152 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core.rb', line 150 def clear_middleware! @middleware = [] end |
.configure_apps { ... } ⇒ Object
Configure Global Project Settings for mounted apps. These can be overloaded in each individual app’s own personal configuration. This can be used like:
93 94 95 96 97 98 99 100 101 102 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core.rb', line 93 def configure_apps(&block) return unless block_given? @@_global_configurations ||= [] @@_global_configurations << block @_global_configuration = lambda do |app| @@_global_configurations.each do |configuration| app.class_eval(&configuration) end end end |
.dependency_paths ⇒ Array<String>
Returns default list of path globs to load as dependencies Appends custom dependency patterns to the be loaded for Padrino.
194 195 196 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/loader.rb', line 194 def dependency_paths @_dependency_paths ||= (dependency_paths_was + Array(module_paths)) end |
.env ⇒ Symbol
Helper method that return PADRINO_ENV.
52 53 54 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core.rb', line 52 def env @_env ||= PADRINO_ENV.to_s.downcase.to_sym end |
.gem(name, main_module) ⇒ Object
Registers a gem with padrino. This relieves the caller from setting up loadpaths by himself and enables Padrino to look up apps in gem folder.
The name given has to be the proper gem name as given in the gemspec.
183 184 185 186 187 188 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core.rb', line 183 def gem(name, main_module) _,spec = Gem.loaded_specs.find { |spec_name, spec| spec_name == name } gems << spec modules << main_module spec.full_gem_path end |
.gems ⇒ Object
Returns all currently known padrino gems.
194 195 196 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core.rb', line 194 def gems @gems ||= [] end |
.insert_mounted_app(mounter) ⇒ Object
Inserts a Mounter object into the mounted applications (avoids duplicates)
218 219 220 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/mounter.rb', line 218 def insert_mounted_app(mounter) Padrino.mounted_apps.push(mounter) unless Padrino.mounted_apps.include?(mounter) end |
.load! ⇒ Boolean
Requires necessary dependencies as well as application files from root lib and models.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/loader.rb', line 61 def load! return false if loaded? t = Time.now @_called_from = first_caller Padrino.set_encoding Padrino.set_load_paths(*load_paths) # We set the padrino load paths Padrino::Logger.setup! # Initialize our logger Padrino.require_dependencies("#{root}/config/database.rb", :nodeps => true) # Be sure to don't remove constants from dbs. Padrino::Reloader.lock! # Now we can remove constant from here to down Padrino.before_load.each(&:call) # Run before hooks Padrino.dependency_paths.each { |path| Padrino.require_dependencies(path) } Padrino.after_load.each(&:call) # Run after hooks Padrino::Reloader.run! Thread.current[:padrino_loaded] = true Padrino.logger.devel "Loaded Padrino in #{Time.now - t} seconds" end |
.load_paths ⇒ Array<String>
The used $LOAD_PATHS from Padrino.
49 50 51 52 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/loader.rb', line 49 def load_paths @_load_paths_was = %w(lib models shared).map { |path| Padrino.root(path) } @_load_paths ||= @_load_paths_was end |
.loaded? ⇒ Boolean
Determines whether Padrino was loaded with load!.
121 122 123 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/loader.rb', line 121 def loaded? Thread.current[:padrino_loaded] end |
.logger ⇒ Padrino::Logger
15 16 17 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/logger.rb', line 15 def self.logger Padrino::Logger.logger end |
.logger=(value) ⇒ Object
Set the padrino logger
36 37 38 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/logger.rb', line 36 def self.logger=(value) Padrino::Logger.logger = value end |
.middleware ⇒ Array<Array<Class, Array, Proc>>
A Rack::Builder object that allows to add middlewares in front of all Padrino applications.
140 141 142 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core.rb', line 140 def middleware @middleware ||= [] end |
.modules ⇒ Object
All loaded Padrino modules.
202 203 204 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core.rb', line 202 def modules @modules ||= [] end |
.mount(name, options = {}) ⇒ Object
Mounts a new sub-application onto Padrino project
230 231 232 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/mounter.rb', line 230 def mount(name, ={}) Mounter.new(name, ) end |
.mounted_apps ⇒ Array
Returns the mounted padrino applications (MountedApp objects).
209 210 211 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/mounter.rb', line 209 def mounted_apps @mounted_apps ||= [] end |
.reload! ⇒ Object
Method for reloading required applications and their files.
100 101 102 103 104 105 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/loader.rb', line 100 def reload! return unless Padrino::Reloader.changed? Padrino.before_load.each(&:call) # Run before hooks Padrino::Reloader.reload! # detects the modified files Padrino.after_load.each(&:call) # Run after hooks end |
.require_dependencies(*paths) ⇒ Object
Attempts to require all dependency libs that we need. If you use this method we can perform correctly a Padrino.reload! Another good thing that this method are dependency check, for example:
# models
# \-- a.rb => require something of b.rb
# \-- b.rb
In the example above if we do:
Dir["/models/*.rb"].each { |r| require r }
we get an error, because we try to require first a.rb
that need something of b.rb
.
With this method we don’t have this problem.
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/loader.rb', line 149 def require_dependencies(*paths) = paths. # Extract all files to load files = paths.flatten.map { |path| Dir[path] }.flatten.uniq.sort while files.present? # List of errors and failed files errors, failed = [], [] # We need a size to make sure things are loading size_at_start = files.size # Now we try to require our dependencies, we dup files # so we don't perform delete on the original array during # iteration, this prevent problems with rubinus files.dup.each do |file| begin Padrino::Reloader.safe_load(file, .dup) files.delete(file) rescue NameError, LoadError => e Padrino.logger.devel "Problem while loading #{file}: #{e.to_s}" errors << e failed << file rescue Exception => e raise e end end # Stop processing if nothing loads or if everything has loaded raise errors.last if files.size == size_at_start && files.present? break if files.empty? end end |
.root(*args) ⇒ String
Helper method for file references.
42 43 44 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core.rb', line 42 def root(*args) File.(File.join(PADRINO_ROOT, *args)) end |
.ruby_command ⇒ String
Return the path to the ruby interpreter taking into account multiple installations and windows extensions.
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/command.rb', line 28 def self.ruby_command @ruby_command ||= begin ruby = File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name']) ruby << RbConfig::CONFIG['EXEEXT'] # escape string in case path to ruby executable contain spaces. ruby.sub!(/.*\s.*/m, '"\&"') ruby end end |
.run!(options = {}) ⇒ Object
Runs the Padrino apps as a self-hosted server using: thin, mongrel, or webrick in that order.
10 11 12 13 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/server.rb', line 10 def self.run!(={}) Padrino.load! Server.start(Padrino.application, ) end |
.set_encoding ⇒ NilClass
Set Encoding.default_internal
and Encoding.default_external
to Encoding::UFT_8
.
Please note that in 1.9.2
with some template engines like haml
you should turn off Encoding.default_internal to prevent problems.
123 124 125 126 127 128 129 130 131 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core.rb', line 123 def set_encoding if RUBY_VERSION < '1.9' $KCODE='u' else Encoding.default_external = Encoding::UTF_8 Encoding.default_internal = Encoding::UTF_8 end nil end |
.set_load_paths(*paths) ⇒ Object
Concat to $LOAD_PATH the given paths.
204 205 206 207 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/loader.rb', line 204 def set_load_paths(*paths) $:.concat(paths); load_paths.concat(paths) $:.uniq!; load_paths.uniq! end |
.use(m, *args) { ... } ⇒ Object
Convenience method for adding a Middleware to the whole padrino app.
166 167 168 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core.rb', line 166 def use(m, *args, &block) middleware << [m, args, block] end |
Instance Method Details
#RUBY_IGNORE_CALLERS ⇒ Object
Add rubinius (and hopefully other VM implementations) ignore patterns …
27 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/caller.rb', line 27 PADRINO_IGNORE_CALLERS.concat(RUBY_IGNORE_CALLERS) |