monk-glue 0.0.1
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.
- data/LICENSE +19 -0
- data/lib/monk/glue.rb +74 -0
- data/lib/monk/glue/logger.rb +11 -0
- data/lib/monk/glue/reloader.rb +45 -0
- data/lib/monk/glue/settings.rb +22 -0
- data/monk-glue.gemspec +13 -0
- metadata +63 -0
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2008 Michel Martens and Damian Janowski
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/lib/monk/glue.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# This file contains the bootstraping code for a Monk application.
|
2
|
+
RACK_ENV = ENV["RACK_ENV"] ||= "development" unless defined? RACK_ENV
|
3
|
+
|
4
|
+
require "sinatra/base"
|
5
|
+
require "haml"
|
6
|
+
require "sass"
|
7
|
+
|
8
|
+
Monk = Module.new unless defined? Monk
|
9
|
+
|
10
|
+
class Monk::Glue < Sinatra::Base
|
11
|
+
|
12
|
+
# Helper method for file references.
|
13
|
+
#
|
14
|
+
# @param args [Array] Path components relative to ROOT_DIR.
|
15
|
+
# @example Referencing a file in config called settings.yml:
|
16
|
+
# root_path("config", "settings.yml")
|
17
|
+
def self.root_path(*args)
|
18
|
+
File.join(ROOT_DIR, *args)
|
19
|
+
end
|
20
|
+
|
21
|
+
# @see Monk::Glue.root_path
|
22
|
+
def root_path(*args)
|
23
|
+
self.class.root_path(*args)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Set option root_dir. Skleton might have defined ROOT_DIR
|
27
|
+
set(:roo_dir, defined?(ROOT_DIR) ? ROOT_DIR : $0) unless respond_to? :roo_dir
|
28
|
+
|
29
|
+
set :dump_errors, true
|
30
|
+
set :logging, true
|
31
|
+
set :methodoverride, true
|
32
|
+
set :raise_errors, Proc.new { test? }
|
33
|
+
set :root, root_path
|
34
|
+
set :run, Proc.new { $0 == app_file }
|
35
|
+
set :show_exceptions, Proc.new { development? }
|
36
|
+
set :static, true
|
37
|
+
set :views, root_path("app", "views")
|
38
|
+
|
39
|
+
use Rack::Session::Cookie
|
40
|
+
|
41
|
+
configure :development do
|
42
|
+
require "monk/glue/reloader"
|
43
|
+
|
44
|
+
use Monk::Glue::Reloader
|
45
|
+
end
|
46
|
+
|
47
|
+
configure :development, :test do
|
48
|
+
begin
|
49
|
+
require "ruby-debug"
|
50
|
+
rescue LoadError
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
helpers do
|
55
|
+
# TODO Add documentation.
|
56
|
+
def haml(template, options = {}, locals = {})
|
57
|
+
options[:escape_html] = true unless options.include?(:escape_html)
|
58
|
+
super(template, options, locals)
|
59
|
+
end
|
60
|
+
|
61
|
+
# TODO Add documentation.
|
62
|
+
def partial(template, locals = {})
|
63
|
+
haml(template, {:layout => false}, locals)
|
64
|
+
end
|
65
|
+
|
66
|
+
%w[environment production? development? test?].each do |meth|
|
67
|
+
define_method(meth) { |*a| Main.send(meth, *a) }
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
require "monk/glue/logger"
|
74
|
+
require "monk/glue/settings"
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
# TODO Add documentation.
|
4
|
+
def logger
|
5
|
+
$logger ||= begin
|
6
|
+
$logger = ::Logger.new(root_path("log", "#{RACK_ENV}.log"))
|
7
|
+
$logger.level = ::Logger.const_get((settings(:log_level) || :warn).to_s.upcase)
|
8
|
+
$logger.datetime_format = "%Y-%m-%d %H:%M:%S"
|
9
|
+
$logger
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
class Monk::Glue::Reloader
|
2
|
+
def initialize(app, app_class = Main)
|
3
|
+
@app = app
|
4
|
+
@app_class = app_class
|
5
|
+
@last = last_mtime
|
6
|
+
end
|
7
|
+
|
8
|
+
def call(env)
|
9
|
+
current = last_mtime
|
10
|
+
|
11
|
+
if current > @last
|
12
|
+
if Thread.list.size > 1
|
13
|
+
Thread.exclusive { reload! }
|
14
|
+
else
|
15
|
+
reload!
|
16
|
+
end
|
17
|
+
|
18
|
+
@last = current
|
19
|
+
end
|
20
|
+
|
21
|
+
@app.call(env)
|
22
|
+
end
|
23
|
+
|
24
|
+
def reload!
|
25
|
+
files.each do |file|
|
26
|
+
$LOADED_FEATURES.delete(file)
|
27
|
+
end
|
28
|
+
|
29
|
+
@app_class.reset!
|
30
|
+
|
31
|
+
require @app_class.app_file
|
32
|
+
end
|
33
|
+
|
34
|
+
# Returns the timestamp for the most recently modified app file.
|
35
|
+
def last_mtime
|
36
|
+
files.map do |file|
|
37
|
+
::File.stat(file).mtime
|
38
|
+
end.max
|
39
|
+
end
|
40
|
+
|
41
|
+
# Returns the list of application files.
|
42
|
+
def files
|
43
|
+
Dir[Main.root_path("app", "**", "*.rb")] + [@app_class.app_file]
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
class Monk::Glue < Sinatra::Base
|
4
|
+
|
5
|
+
# TODO Add documentation.
|
6
|
+
def self.settings(key)
|
7
|
+
@settings ||= YAML.load_file(root_path("config", "settings.yml"))[RACK_ENV.to_sym]
|
8
|
+
|
9
|
+
unless @settings.include?(key)
|
10
|
+
message = "No setting defined for #{key.inspect}."
|
11
|
+
defined?(logger) ? logger.warn(message) : $stderr.puts(message)
|
12
|
+
end
|
13
|
+
|
14
|
+
@settings[key]
|
15
|
+
end
|
16
|
+
|
17
|
+
def settings(key)
|
18
|
+
self.class.settings(key)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
data/monk-glue.gemspec
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "monk-glue"
|
3
|
+
s.version = "0.0.1"
|
4
|
+
s.summary = "Monk, the glue framework"
|
5
|
+
s.description = "Monk is a glue framework for web development. It means that instead of installing all the tools you need for your projects, you can rely on a git repository and a list of dependencies, and Monk will care of the rest. By default, it ships with a Sinatra application that includes Contest, Stories, Webrat, Ohm and some other niceties, along with a structure and helpful documentation to get your hands wet in no time."
|
6
|
+
s.authors = ["Damian Janowski", "Michel Martens"]
|
7
|
+
s.email = ["djanowski@dimaion.com", "michel@soveran.com"]
|
8
|
+
s.homepage = "http://monkrb.com"
|
9
|
+
|
10
|
+
s.rubyforge_project = "monk"
|
11
|
+
|
12
|
+
s.files = ["LICENSE", "lib/monk/glue/logger.rb", "lib/monk/glue/reloader.rb", "lib/monk/glue/settings.rb", "lib/monk/glue.rb", "monk-glue.gemspec"]
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: monk-glue
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Damian Janowski
|
8
|
+
- Michel Martens
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2009-09-16 00:00:00 +02:00
|
14
|
+
default_executable:
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description: Monk is a glue framework for web development. It means that instead of installing all the tools you need for your projects, you can rely on a git repository and a list of dependencies, and Monk will care of the rest. By default, it ships with a Sinatra application that includes Contest, Stories, Webrat, Ohm and some other niceties, along with a structure and helpful documentation to get your hands wet in no time.
|
18
|
+
email:
|
19
|
+
- djanowski@dimaion.com
|
20
|
+
- michel@soveran.com
|
21
|
+
executables: []
|
22
|
+
|
23
|
+
extensions: []
|
24
|
+
|
25
|
+
extra_rdoc_files: []
|
26
|
+
|
27
|
+
files:
|
28
|
+
- LICENSE
|
29
|
+
- lib/monk/glue/logger.rb
|
30
|
+
- lib/monk/glue/reloader.rb
|
31
|
+
- lib/monk/glue/settings.rb
|
32
|
+
- lib/monk/glue.rb
|
33
|
+
- monk-glue.gemspec
|
34
|
+
has_rdoc: true
|
35
|
+
homepage: http://monkrb.com
|
36
|
+
licenses: []
|
37
|
+
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: "0"
|
48
|
+
version:
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
55
|
+
requirements: []
|
56
|
+
|
57
|
+
rubyforge_project: monk
|
58
|
+
rubygems_version: 1.3.5
|
59
|
+
signing_key:
|
60
|
+
specification_version: 3
|
61
|
+
summary: Monk, the glue framework
|
62
|
+
test_files: []
|
63
|
+
|