ramaze 2008.06 → 2008.11
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +6 -6
- data/Rakefile +33 -3
- data/bin/ramaze +18 -0
- data/doc/CHANGELOG +960 -0
- data/doc/LEGAL +5 -1
- data/doc/meta/announcement.txt +20 -36
- data/doc/tutorial/todolist.html +421 -313
- data/doc/tutorial/todolist.mkd +33 -16
- data/examples/app/blog/spec/blog.rb +3 -3
- data/examples/app/rapaste/controller/paste.rb +8 -1
- data/examples/app/rapaste/model/paste.rb +3 -0
- data/examples/app/rapaste/spec/rapaste.rb +3 -1
- data/examples/app/rapaste/start.rb +3 -2
- data/examples/app/sourceview/public/sourceview.js +2 -2
- data/examples/app/todolist/spec/todolist.rb +6 -6
- data/examples/app/todolist/template/index.xhtml +1 -1
- data/examples/app/whywiki/spec/whywiki.rb +2 -2
- data/examples/app/wikore/spec/wikore.rb +2 -2
- data/examples/app/wikore/src/model.rb +4 -3
- data/examples/app/wiktacular/spec/wiktacular.rb +7 -7
- data/examples/basic/simple.rb +2 -2
- data/examples/helpers/paginate.rb +71 -0
- data/examples/misc/simple_auth.rb +20 -8
- data/lib/proto/controller/init.rb +10 -0
- data/lib/proto/controller/main.rb +1 -3
- data/lib/proto/model/init.rb +4 -0
- data/lib/proto/public/dispatch.fcgi +1 -1
- data/lib/proto/spec/main.rb +2 -1
- data/lib/proto/start.rb +3 -3
- data/lib/proto/start.ru +1 -1
- data/lib/proto/view/error.xhtml +4 -4
- data/lib/ramaze.rb +8 -3
- data/lib/ramaze/action.rb +6 -6
- data/lib/ramaze/adapter.rb +1 -6
- data/lib/ramaze/adapter/base.rb +30 -27
- data/lib/ramaze/adapter/cgi.rb +1 -0
- data/lib/ramaze/cache.rb +1 -3
- data/lib/ramaze/cache/memcached.rb +3 -5
- data/lib/ramaze/contrib/auto_params.rb +2 -2
- data/lib/ramaze/contrib/auto_params/get_args.rb +2 -1
- data/lib/ramaze/contrib/gems.rb +17 -18
- data/lib/ramaze/contrib/gzip_filter.rb +22 -9
- data/lib/ramaze/contrib/maruku_uv.rb +59 -0
- data/lib/ramaze/contrib/profiling.rb +1 -1
- data/lib/ramaze/contrib/rest.rb +16 -13
- data/lib/ramaze/contrib/sequel/create_join.rb +25 -0
- data/lib/ramaze/contrib/sequel/form_field.rb +129 -0
- data/lib/ramaze/contrib/sequel/image.rb +198 -0
- data/lib/ramaze/contrib/sequel/relation.rb +82 -0
- data/lib/ramaze/controller.rb +33 -34
- data/lib/ramaze/controller/resolve.rb +29 -9
- data/lib/ramaze/current.rb +60 -20
- data/lib/ramaze/current/request.rb +8 -7
- data/lib/ramaze/current/response.rb +15 -3
- data/lib/ramaze/current/session/flash.rb +8 -0
- data/lib/ramaze/dispatcher.rb +17 -9
- data/lib/ramaze/dispatcher/action.rb +4 -5
- data/lib/ramaze/dispatcher/directory.rb +1 -1
- data/lib/ramaze/dispatcher/error.rb +4 -4
- data/lib/ramaze/dispatcher/file.rb +4 -4
- data/lib/ramaze/gestalt.rb +15 -20
- data/lib/ramaze/helper/cgi.rb +7 -15
- data/lib/ramaze/helper/formatting.rb +41 -1
- data/lib/ramaze/helper/httpdigest.rb +20 -7
- data/lib/ramaze/helper/link.rb +4 -6
- data/lib/ramaze/helper/paginate.rb +233 -0
- data/lib/ramaze/helper/redirect.rb +1 -1
- data/lib/ramaze/helper/rest.rb +1 -1
- data/lib/ramaze/helper/thread.rb +17 -0
- data/lib/ramaze/helper/ultraviolet.rb +44 -0
- data/lib/ramaze/helper/user.rb +4 -9
- data/lib/ramaze/log.rb +2 -2
- data/lib/ramaze/log/analogger.rb +21 -23
- data/lib/ramaze/log/growl.rb +21 -23
- data/lib/ramaze/log/hub.rb +1 -1
- data/lib/ramaze/log/informer.rb +97 -99
- data/lib/ramaze/log/knotify.rb +14 -16
- data/lib/ramaze/log/logger.rb +11 -13
- data/lib/ramaze/log/logging.rb +61 -63
- data/lib/ramaze/log/rotatinginformer.rb +168 -0
- data/lib/ramaze/log/syslog.rb +41 -31
- data/lib/ramaze/log/xosd.rb +70 -72
- data/lib/ramaze/option.rb +9 -6
- data/lib/ramaze/option/holder.rb +5 -27
- data/lib/ramaze/reloader.rb +186 -0
- data/lib/ramaze/setup.rb +1 -1
- data/lib/ramaze/snippets.rb +13 -0
- data/lib/ramaze/snippets/array/put_within.rb +31 -24
- data/lib/ramaze/snippets/binding/locals.rb +23 -11
- data/lib/ramaze/snippets/dictionary.rb +2 -2
- data/lib/ramaze/snippets/fiber.rb +63 -0
- data/lib/ramaze/snippets/kernel/constant.rb +36 -21
- data/lib/ramaze/snippets/kernel/pretty_inspect.rb +12 -6
- data/lib/ramaze/snippets/numeric/filesize_format.rb +24 -17
- data/lib/ramaze/snippets/numeric/time.rb +63 -0
- data/lib/ramaze/snippets/object/__dir__.rb +29 -0
- data/lib/ramaze/snippets/object/acquire.rb +40 -0
- data/lib/ramaze/snippets/object/instance_variable_defined.rb +16 -5
- data/lib/ramaze/snippets/object/pretty.rb +14 -4
- data/lib/ramaze/snippets/object/scope.rb +14 -7
- data/lib/ramaze/snippets/ordered_set.rb +25 -14
- data/lib/ramaze/snippets/proc/locals.rb +17 -9
- data/lib/ramaze/snippets/ramaze/deprecated.rb +13 -0
- data/lib/ramaze/snippets/ramaze/fiber.rb +24 -0
- data/lib/ramaze/snippets/ramaze/state.rb +86 -0
- data/lib/ramaze/snippets/ramaze/struct.rb +45 -0
- data/lib/ramaze/snippets/string/camel_case.rb +13 -8
- data/lib/ramaze/snippets/string/color.rb +24 -20
- data/lib/ramaze/snippets/string/each.rb +14 -3
- data/lib/ramaze/snippets/string/end_with.rb +20 -0
- data/lib/ramaze/snippets/string/esc.rb +26 -21
- data/lib/ramaze/snippets/string/ord.rb +12 -6
- data/lib/ramaze/snippets/string/snake_case.rb +13 -7
- data/lib/ramaze/snippets/string/start_with.rb +16 -5
- data/lib/ramaze/snippets/string/unindent.rb +23 -15
- data/lib/ramaze/snippets/thread/into.rb +3 -3
- data/lib/ramaze/spec/helper/bacon.rb +5 -5
- data/lib/ramaze/spec/helper/mock_http.rb +1 -1
- data/lib/ramaze/spec/helper/pretty_output.rb +2 -2
- data/lib/ramaze/spec/helper/snippets.rb +8 -0
- data/lib/ramaze/template.rb +4 -1
- data/lib/ramaze/template/ezamar/textpow.syntax +34 -0
- data/lib/ramaze/template/maruku.rb +34 -0
- data/lib/ramaze/template/tagz.rb +2 -2
- data/lib/ramaze/template/xslt.rb +2 -2
- data/lib/ramaze/tool/create.rb +27 -53
- data/lib/ramaze/tool/localize.rb +8 -4
- data/lib/ramaze/tool/mime.rb +11 -1
- data/lib/ramaze/tool/project_creator.rb +110 -0
- data/lib/ramaze/trinity.rb +4 -1
- data/lib/ramaze/version.rb +1 -1
- data/lib/vendor/bacon.rb +323 -0
- data/rake_tasks/gem.rake +10 -1
- data/rake_tasks/maintenance.rake +40 -2
- data/rake_tasks/metric.rake +24 -0
- data/rake_tasks/release.rake +17 -4
- data/rake_tasks/spec.rake +1 -2
- data/ramaze.gemspec +549 -495
- data/spec/contrib/auto_params.rb +3 -3
- data/spec/contrib/profiling.rb +2 -2
- data/spec/examples/simple_auth.rb +2 -2
- data/spec/examples/templates/template_haml.rb +0 -2
- data/spec/ramaze/action/file_cache.rb +22 -0
- data/spec/ramaze/adapter.rb +2 -2
- data/spec/ramaze/controller/actionless_templates.rb +1 -1
- data/spec/ramaze/controller/subclass.rb +15 -0
- data/spec/ramaze/controller/template_resolving.rb +1 -1
- data/spec/ramaze/controller/view/bar.xhtml +1 -0
- data/spec/ramaze/controller/view/base/another.xhtml +1 -0
- data/spec/ramaze/current/session.rb +1 -1
- data/spec/ramaze/dispatcher/file.rb +2 -2
- data/spec/ramaze/helper/aspect.rb +26 -17
- data/spec/ramaze/helper/formatting.rb +13 -0
- data/spec/ramaze/log/informer.rb +10 -10
- data/spec/ramaze/log/syslog.rb +67 -4
- data/spec/ramaze/rewrite.rb +1 -1
- data/spec/ramaze/route.rb +1 -1
- data/spec/ramaze/struct.rb +47 -0
- data/spec/ramaze/template/markaby.rb +1 -1
- data/spec/ramaze/template/tagz.rb +1 -1
- data/spec/snippets/binding/locals.rb +9 -0
- data/spec/snippets/numeric/time.rb +12 -0
- data/spec/snippets/{kernel → object}/__dir__.rb +0 -0
- data/spec/snippets/{kernel → object}/acquire.rb +0 -0
- metadata +90 -81
- data/cache.yaml +0 -7
- data/examples/app/rammit/spec/rammit.rb +0 -31
- data/examples/app/rammit/src/controller/main.rb +0 -3
- data/examples/app/rammit/src/controller/page.rb +0 -16
- data/examples/app/rammit/src/model.rb +0 -33
- data/examples/app/rammit/start.rb +0 -8
- data/examples/app/rammit/template/index.xhtml +0 -14
- data/examples/app/rammit/template/page/view.xhtml +0 -4
- data/lib/ramaze/snippets/kernel/__dir__.rb +0 -23
- data/lib/ramaze/snippets/kernel/acquire.rb +0 -34
- data/lib/ramaze/snippets/object/thread_accessor.rb +0 -5
- data/lib/ramaze/snippets/ramaze/thread_accessor.rb +0 -58
- data/lib/ramaze/snippets/struct/fill.rb +0 -23
- data/lib/ramaze/snippets/struct/values_at.rb +0 -39
- data/lib/ramaze/snippets/symbol/to_proc.rb +0 -24
- data/lib/ramaze/sourcereload.rb +0 -176
- data/spec/snippets/struct/fill.rb +0 -26
- data/spec/snippets/struct/values_at.rb +0 -52
- data/spec/snippets/symbol/to_proc.rb +0 -13
@@ -1,10 +1,10 @@
|
|
1
1
|
# Copyright (c) 2008 Michael Fellinger m.fellinger@gmail.com
|
2
2
|
# All files in this distribution are subject to the terms of the Ruby license.
|
3
3
|
|
4
|
+
# Extensions for Thread
|
5
|
+
|
4
6
|
class Thread
|
5
|
-
# Copy
|
6
|
-
# :action, :response, :request, :session,
|
7
|
-
# :task, :adapter, :controller, :exception
|
7
|
+
# Copy all thread variables into the new thread
|
8
8
|
|
9
9
|
def self.into *args
|
10
10
|
Thread.new(Thread.current, *args) do |thread, *args|
|
@@ -1,7 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
require
|
5
|
-
|
1
|
+
libdir = File.expand_path(File.join(File.dirname(__FILE__), '../../../'))
|
2
|
+
$LOAD_PATH.unshift libdir
|
3
|
+
require 'vendor/bacon'
|
4
|
+
require 'ramaze/spec/helper/pretty_output'
|
6
5
|
Bacon.extend Bacon::PrettyOutput
|
6
|
+
# Bacon.extend Bacon::TestUnitOutput
|
7
7
|
Bacon.summary_on_exit
|
@@ -57,7 +57,7 @@ module MockHTTP
|
|
57
57
|
def make_query query
|
58
58
|
return query unless query and not query.is_a?(String)
|
59
59
|
query.map{|key, value|
|
60
|
-
"#{
|
60
|
+
"#{Rack::Utils.escape(key)}=#{Rack::Utils.escape(value)}"
|
61
61
|
}.join('&')
|
62
62
|
end
|
63
63
|
end
|
@@ -16,9 +16,9 @@ module Bacon
|
|
16
16
|
error = yield
|
17
17
|
|
18
18
|
unless error.empty?
|
19
|
-
if defined?(Ramaze::Logging
|
19
|
+
if defined?(Ramaze::Logging)
|
20
20
|
puts '', " #{NAME} -- #{description} [FAILED]".center(70, '-'), ''
|
21
|
-
colors = Ramaze::
|
21
|
+
colors = Ramaze::Logger::Informer::COLORS
|
22
22
|
|
23
23
|
until RamazeLogger.history.empty?
|
24
24
|
tag, line = RamazeLogger.history.shift
|
@@ -1,6 +1,14 @@
|
|
1
1
|
if caller
|
2
2
|
snippet = caller.grep(%r!spec/snippets/!).first.split(':').first
|
3
3
|
require File.expand_path(snippet).gsub('/spec/', '/lib/ramaze/')
|
4
|
+
|
5
|
+
if defined?(Ramaze::CoreExtensions)
|
6
|
+
Ramaze::CoreExtensions.constants.each do |const|
|
7
|
+
ext = Ramaze::CoreExtensions.const_get(const)
|
8
|
+
into = Module.const_get(const)
|
9
|
+
into.__send__(:include, ext)
|
10
|
+
end
|
11
|
+
end
|
4
12
|
end
|
5
13
|
|
6
14
|
require 'lib/ramaze/spec/helper/bacon'
|
data/lib/ramaze/template.rb
CHANGED
@@ -16,7 +16,10 @@ module Ramaze
|
|
16
16
|
|
17
17
|
ENGINES = {} unless defined?(ENGINES)
|
18
18
|
|
19
|
-
AVAILABLE_ENGINES = %w[
|
19
|
+
AVAILABLE_ENGINES = %w[
|
20
|
+
Amrita2 Builder Erubis Haml Liquid Markaby Maruku Nagoro None RedCloth
|
21
|
+
Remarkably Sass Tagz Tenjin XSLT
|
22
|
+
]
|
20
23
|
|
21
24
|
AVAILABLE_ENGINES.each do |const|
|
22
25
|
autoload(const, "ramaze/template/#{const.downcase}")
|
@@ -0,0 +1,34 @@
|
|
1
|
+
---
|
2
|
+
name: HTML (Ezamar)
|
3
|
+
fileTypes:
|
4
|
+
- xhtml
|
5
|
+
scopeName: text.html.ruby
|
6
|
+
uuid: 45D7E1FC-7D0B-4205-A1A2-3D10BB555A5C
|
7
|
+
foldingStartMarker: |-
|
8
|
+
(?x)
|
9
|
+
(<(?i:head|body|table|thead|tbody|tfoot|tr|div|select|fieldset|style|script|ul|ol|form|dl)\b.*?>
|
10
|
+
|<!--(?!.*-->)
|
11
|
+
|\{\s*($|\?>\s*$|//|/\*(.*\*/\s*$|(?!.*?\*/)))
|
12
|
+
)
|
13
|
+
patterns:
|
14
|
+
- name: source.ruby.ezamar.embedded.html
|
15
|
+
captures:
|
16
|
+
"0":
|
17
|
+
name: punctuation.section.embedded.ruby
|
18
|
+
begin: "<?r"
|
19
|
+
end: "?>"
|
20
|
+
patterns:
|
21
|
+
- name: comment.line.number-sign.ruby
|
22
|
+
captures:
|
23
|
+
"1":
|
24
|
+
name: punctuation.definition.comment.ruby
|
25
|
+
match: (#).*?(?=-?\?>)
|
26
|
+
- include: source.ruby.ezamar
|
27
|
+
- include: text.html.basic
|
28
|
+
foldingStopMarker: |-
|
29
|
+
(?x)
|
30
|
+
(</(?i:head|body|table|thead|tbody|tfoot|tr|div|select|fieldset|style|script|ul|ol|form|dl)>
|
31
|
+
|^\s*-->
|
32
|
+
|(^|\s)\}
|
33
|
+
)
|
34
|
+
keyEquivalent: ^~R
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# Copyright (c) 2008 Michael Fellinger m.fellinger@gmail.com
|
2
|
+
# All files in this distribution are subject to the terms of the Ruby license.
|
3
|
+
|
4
|
+
require 'maruku'
|
5
|
+
|
6
|
+
module Ramaze
|
7
|
+
module Template
|
8
|
+
|
9
|
+
# Is responsible for compiling a template using the Ezamar templating engine.
|
10
|
+
|
11
|
+
class Maruku < Template
|
12
|
+
|
13
|
+
ENGINES[self] = %w[ mkd ]
|
14
|
+
|
15
|
+
class << self
|
16
|
+
|
17
|
+
# Transforms an action into the XHTML code for parsing and returns
|
18
|
+
# the result
|
19
|
+
def transform(action)
|
20
|
+
maruku = wrap_compile(action)
|
21
|
+
maruku.to_html
|
22
|
+
end
|
23
|
+
|
24
|
+
# Compile a template, applying all transformations from the pipeline
|
25
|
+
# and returning an instance of ::Ezamar::Template
|
26
|
+
|
27
|
+
def compile(action, template)
|
28
|
+
::Maruku.new(template)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
data/lib/ramaze/template/tagz.rb
CHANGED
@@ -55,11 +55,11 @@ module Ramaze
|
|
55
55
|
end
|
56
56
|
|
57
57
|
def p *a
|
58
|
-
a.each{|elem| tagz << "#{
|
58
|
+
a.each{|elem| tagz << "#{ Rack::Utils.escape_html elem.inspect }#{ eol }"}
|
59
59
|
end
|
60
60
|
|
61
61
|
def pp *a
|
62
|
-
a.each{|elem| tagz << "#{
|
62
|
+
a.each{|elem| tagz << "#{ Rack::Utils.escape_html PP.pp(elem, '') }#{ eol }"}
|
63
63
|
end
|
64
64
|
|
65
65
|
def eol
|
data/lib/ramaze/template/xslt.rb
CHANGED
@@ -55,8 +55,8 @@ module Ramaze
|
|
55
55
|
end
|
56
56
|
|
57
57
|
# Synchronize the block to run with the mutex
|
58
|
-
def ext_functions_synchronize
|
59
|
-
XSLT_EXT_FUNCTIONS_LOCK.synchronize
|
58
|
+
def ext_functions_synchronize(&block)
|
59
|
+
XSLT_EXT_FUNCTIONS_LOCK.synchronize(&block)
|
60
60
|
end
|
61
61
|
|
62
62
|
# Expose functors
|
data/lib/ramaze/tool/create.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# Copyright (c) 2008 Michael Fellinger m.fellinger@gmail.com
|
2
2
|
# All files in this distribution are subject to the terms of the Ruby license.
|
3
3
|
|
4
|
+
require 'ramaze/tool/project_creator'
|
5
|
+
|
4
6
|
module Ramaze
|
5
7
|
module Tool
|
6
8
|
|
@@ -14,60 +16,32 @@ module Ramaze
|
|
14
16
|
# where project is the directory you want the content put into.
|
15
17
|
|
16
18
|
class Create
|
17
|
-
class << self
|
18
|
-
|
19
|
-
# a method to create a new project by copying the contents of lib/proto
|
20
|
-
# to the position you specify (project)
|
21
|
-
#
|
22
|
-
# It is just a nice wrapper showing you what files/directories are put
|
23
|
-
# in place.
|
24
|
-
|
25
|
-
def create project
|
26
|
-
@basedir = ::Ramaze::BASEDIR / 'proto'
|
27
|
-
@destdir = Dir.pwd / project
|
28
|
-
|
29
|
-
if File.directory?(@destdir)
|
30
|
-
puts "Error: #{project}/ already exists. Rename or delete directory and try again."
|
31
|
-
return
|
32
|
-
end
|
33
|
-
|
34
|
-
puts "Creating project #{project}"
|
35
|
-
|
36
|
-
FileUtils.mkdir_p(project)
|
37
|
-
|
38
|
-
puts "Copying skeleton project to new project (#@destdir)..."
|
39
|
-
|
40
|
-
directories, files =
|
41
|
-
Dir[@basedir / '**' / '*'].partition{ |f| File.directory?(f) }
|
42
|
-
|
43
|
-
# gem packaging removes empty model directory, so add it in ourselves
|
44
|
-
create_dirs(*Array[ @basedir/'model', *directories ].uniq)
|
45
|
-
copy_files(*files)
|
46
|
-
|
47
|
-
puts "\nStart your new ramaze app: ruby #{project}/start.rb"
|
48
|
-
end
|
49
|
-
|
50
|
-
# create the directories recursivly
|
51
|
-
|
52
|
-
def create_dirs(*dirs)
|
53
|
-
dirs.each do |dir|
|
54
|
-
dest = dir.gsub(@basedir, @destdir)
|
55
|
-
|
56
|
-
puts "Create directory: '#{dest}'"
|
57
|
-
FileUtils.mkdir_p(dest)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
# copy the files over
|
62
|
-
|
63
|
-
def copy_files(*files)
|
64
|
-
files.each do |file|
|
65
|
-
dest = file.gsub(@basedir, @destdir)
|
66
19
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
20
|
+
# Default options passed to Create::create
|
21
|
+
# :proto is the directory to duplicate
|
22
|
+
# :amend no files may be overwritten but missing files will be added
|
23
|
+
# :force will overwrite existing files
|
24
|
+
# :layout copy one subdirectory in +proto+
|
25
|
+
|
26
|
+
DEFAULT = {
|
27
|
+
:proto => File.join(::Ramaze::BASEDIR, 'proto'),
|
28
|
+
:amend => false,
|
29
|
+
:force => false,
|
30
|
+
:layout => '/',
|
31
|
+
}
|
32
|
+
|
33
|
+
# Using ProjectCreator to copy all files and directories from lib/proto
|
34
|
+
# to another location.
|
35
|
+
# +options+ are described in the DEFAULT constant and should be:
|
36
|
+
# :force => (true|false|nil)
|
37
|
+
# :amend => (true|false|nil)
|
38
|
+
# :layout => (String|nil)
|
39
|
+
# :proto => String
|
40
|
+
|
41
|
+
def self.create(project, options = {})
|
42
|
+
options = DEFAULT.merge(options)
|
43
|
+
creator = ProjectCreator.new(project, options)
|
44
|
+
creator.create
|
71
45
|
end
|
72
46
|
end
|
73
47
|
end
|
data/lib/ramaze/tool/localize.rb
CHANGED
@@ -63,10 +63,14 @@ module Ramaze
|
|
63
63
|
|
64
64
|
def call(response, options = {})
|
65
65
|
return response unless trait[:enable]
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
response
|
66
|
+
|
67
|
+
body = []
|
68
|
+
|
69
|
+
response.body.each do |chunk|
|
70
|
+
body << localize_body(chunk, options)
|
71
|
+
end
|
72
|
+
|
73
|
+
response.body = body
|
70
74
|
end
|
71
75
|
|
72
76
|
# Localizes a response body. It reacts to a regular expression as given
|
data/lib/ramaze/tool/mime.rb
CHANGED
@@ -15,10 +15,20 @@ module Ramaze
|
|
15
15
|
|
16
16
|
# Get MIME-type for the given filename based on extension.
|
17
17
|
# Answers with an empty string if none is found.
|
18
|
-
def type_for
|
18
|
+
def type_for(file)
|
19
19
|
ext = File.extname(file)
|
20
20
|
trait[:types][ext].to_s
|
21
21
|
end
|
22
|
+
|
23
|
+
def ext_for(mime)
|
24
|
+
exts = []
|
25
|
+
|
26
|
+
trait[:types].each do |ext, mime_type|
|
27
|
+
exts << ext if mime == mime_type
|
28
|
+
end
|
29
|
+
|
30
|
+
exts.sort_by{|e| e.size }.first
|
31
|
+
end
|
22
32
|
end
|
23
33
|
end
|
24
34
|
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
# Copyright (c) 2008 Michael Fellinger m.fellinger@gmail.com
|
2
|
+
# All files in this distribution are subject to the terms of the Ruby license.
|
3
|
+
|
4
|
+
require 'fileutils'
|
5
|
+
require 'find'
|
6
|
+
|
7
|
+
class ProjectCreator
|
8
|
+
PROTO = ['~/.proto/']
|
9
|
+
attr_accessor :name, :options
|
10
|
+
|
11
|
+
def initialize(name, options = {})
|
12
|
+
@name, @options = name, options
|
13
|
+
end
|
14
|
+
|
15
|
+
def target
|
16
|
+
File.expand_path(name)
|
17
|
+
end
|
18
|
+
|
19
|
+
def proto
|
20
|
+
PROTO.map!{|pr| File.expand_path(pr) }
|
21
|
+
proto = options[:proto] ||= PROTO.find{|f| File.directory?(f) }
|
22
|
+
layout = options[:layout] ||= '/'
|
23
|
+
File.expand_path(File.join(proto, layout))
|
24
|
+
end
|
25
|
+
|
26
|
+
def create_root?
|
27
|
+
return true unless File.directory?(target)
|
28
|
+
return true if amend? or force?
|
29
|
+
fatal "%p is a directory, choose different project name or use --amend/--force" % target
|
30
|
+
end
|
31
|
+
|
32
|
+
def got_proto?
|
33
|
+
return true if File.directory?(proto)
|
34
|
+
fatal "Cannot create, %p doesn't exist, use --proto or create the proto directory" % proto
|
35
|
+
end
|
36
|
+
|
37
|
+
def create
|
38
|
+
got_proto?
|
39
|
+
|
40
|
+
puts "Found proto at: %p, proceeding...\n\n" % proto
|
41
|
+
mkdir(relate('/')) if create_root?
|
42
|
+
proceed
|
43
|
+
end
|
44
|
+
|
45
|
+
def proceed
|
46
|
+
files, directories = partition{|path| File.file?(path) }
|
47
|
+
proceed_directories(directories)
|
48
|
+
proceed_files(files)
|
49
|
+
end
|
50
|
+
|
51
|
+
def proceed_files(files)
|
52
|
+
files.each{|file| copy(file, relate(file)) }
|
53
|
+
end
|
54
|
+
|
55
|
+
def proceed_directories(dirs)
|
56
|
+
dirs.each{|dir| mkdir(relate(dir)) }
|
57
|
+
end
|
58
|
+
|
59
|
+
def mkdir(dir)
|
60
|
+
exists = File.directory?(dir)
|
61
|
+
return if exists and amend?
|
62
|
+
return if exists and not force?
|
63
|
+
puts "mkdir(%p)" % dir
|
64
|
+
FileUtils.mkdir_p(dir)
|
65
|
+
end
|
66
|
+
|
67
|
+
def copy(from, to)
|
68
|
+
return unless copy_check(to)
|
69
|
+
puts "copy(%p, %p)" % [from, to]
|
70
|
+
FileUtils.cp(from, to)
|
71
|
+
post_process(to)
|
72
|
+
end
|
73
|
+
|
74
|
+
def copy_check(to)
|
75
|
+
exists = File.file?(to)
|
76
|
+
return if exists and amend?
|
77
|
+
return if exists and not force?
|
78
|
+
return true
|
79
|
+
end
|
80
|
+
|
81
|
+
# Think about a useful way to process the generated files it should be
|
82
|
+
# possible to substitute some things like the project name in the
|
83
|
+
# configuration
|
84
|
+
|
85
|
+
def post_process(file)
|
86
|
+
return
|
87
|
+
source = File.read(file)
|
88
|
+
File.open(file, 'w+') do |io|
|
89
|
+
io.write(source.gsub('$project', "'#@name'"))
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def relate(path)
|
94
|
+
File.join(target, path.to_s.sub(proto, ''))
|
95
|
+
end
|
96
|
+
|
97
|
+
def amend?; options[:amend] end
|
98
|
+
def force?; options[:force] end
|
99
|
+
|
100
|
+
def fatal(message)
|
101
|
+
warn message
|
102
|
+
exit 1
|
103
|
+
end
|
104
|
+
|
105
|
+
def each
|
106
|
+
Dir["#{proto}/**/*"].each{|path| yield(path) }
|
107
|
+
end
|
108
|
+
|
109
|
+
include Enumerable
|
110
|
+
end
|
data/lib/ramaze/trinity.rb
CHANGED
@@ -2,12 +2,15 @@
|
|
2
2
|
# All files in this distribution are subject to the terms of the Ruby license.
|
3
3
|
|
4
4
|
module Ramaze
|
5
|
+
STATE = State.new
|
5
6
|
|
6
7
|
# The module to be included into the Controller it basically just provides
|
7
8
|
# #request, #response and #session, each accessing Thread.current to
|
8
9
|
# retrieve the demanded object
|
9
10
|
|
10
11
|
module Trinity
|
11
|
-
|
12
|
+
extend StateAccessor
|
13
|
+
|
14
|
+
state_accessor :request, :response, :session
|
12
15
|
end
|
13
16
|
end
|
data/lib/ramaze/version.rb
CHANGED