manveru-ramaze 2009.04.01 → 2009.04.08
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +201 -0
- data/MANIFEST +10 -8
- data/Rakefile +19 -3
- data/bin/ramaze +142 -55
- data/doc/tutorial/todolist.html +83 -5
- data/doc/tutorial/todolist.txt +85 -33
- data/examples/app/blog/start.rb +1 -1
- data/examples/app/todolist/model/init.rb +3 -0
- data/examples/templates/template_redcloth.rb +2 -2
- data/lib/proto/layout/{default.nag → default.xhtml} +0 -0
- data/lib/proto/view/{index.nag → index.xhtml} +0 -0
- data/lib/proto/view/{page.nag → page.xhtml} +0 -0
- data/lib/ramaze/app.rb +5 -5
- data/lib/ramaze/cache.rb +3 -2
- data/lib/ramaze/cache/localmemcache.rb +56 -0
- data/lib/ramaze/contrib/app_graph.rb +64 -0
- data/lib/ramaze/controller/default.rb +5 -0
- data/lib/ramaze/helper.rb +6 -16
- data/lib/ramaze/helper/httpdigest.rb +1 -1
- data/lib/ramaze/helper/link.rb +2 -5
- data/lib/ramaze/helper/partial.rb +85 -10
- data/lib/ramaze/request.rb +20 -0
- data/lib/ramaze/snippets/ramaze/deprecated.rb +0 -1
- data/lib/ramaze/spec.rb +10 -0
- data/lib/ramaze/tool/create.rb +48 -0
- data/lib/ramaze/tool/project_creator.rb +111 -0
- data/lib/ramaze/version.rb +1 -1
- data/ramaze.gemspec +3 -9
- data/spec/examples/templates/template_markaby.rb +1 -1
- data/spec/ramaze/cache/localmemcache.rb +49 -0
- data/spec/ramaze/helper/sequel_form.rb +1 -1
- data/tasks/bacon.rake +38 -21
- metadata +12 -31
- data/examples/templates/template_xslt.rb +0 -48
- data/examples/templates/view/external.xsl +0 -57
- data/lib/ramaze/contrib/sequel/fill.rb +0 -12
- data/spec/contrib/sequel/fill.rb +0 -47
- data/spec/examples/templates/template_xslt.rb +0 -10
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'set'
|
2
|
+
|
3
|
+
# require 'ramaze/contrib/app_graph'
|
4
|
+
#
|
5
|
+
# graph = AppGraph.new
|
6
|
+
# graph.generate
|
7
|
+
# graph.show
|
8
|
+
|
9
|
+
class AppGraph
|
10
|
+
def initialize
|
11
|
+
@out = Set.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def generate
|
15
|
+
Ramaze::AppMap.to_hash.each do |location, app|
|
16
|
+
connect(location => app.name)
|
17
|
+
|
18
|
+
app.url_map.to_hash.each do |c_location, c_node|
|
19
|
+
connect(app.name => c_node)
|
20
|
+
connect(c_node.mapping => c_node)
|
21
|
+
|
22
|
+
c_node.update_template_mappings
|
23
|
+
c_node.view_templates.each do |wish, mapping|
|
24
|
+
mapping.each do |action_name, template|
|
25
|
+
action_path = File.join(c_node.mapping, action_name)
|
26
|
+
connect(c_node => action_path, action_path => template)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
c_node.update_method_arities
|
31
|
+
c_node.method_arities.each do |method, arity|
|
32
|
+
action_path = File.join(c_node.mapping, method.to_s)
|
33
|
+
connect(action_path => "#{c_node}##{method}[#{arity}]", c_node => action_path)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def connect(hash)
|
40
|
+
hash.each do |from, to|
|
41
|
+
@out << (" %p -> %p;" % [from.to_s, to.to_s])
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def write_dot
|
46
|
+
File.open('graph.dot', 'w+') do |dot|
|
47
|
+
dot.puts 'digraph appmap {'
|
48
|
+
dot.puts(*@out)
|
49
|
+
dot.puts '}'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def show
|
54
|
+
write_dot
|
55
|
+
options = {
|
56
|
+
'rankdir' => 'LR',
|
57
|
+
'splines' => 'true',
|
58
|
+
'overlap' => 'false',
|
59
|
+
}
|
60
|
+
args = options.map{|k,v| "-G#{k}=#{v}" }
|
61
|
+
system("dot -O -Tpng #{args.join(' ')} graph.dot")
|
62
|
+
system('feh graph.dot.png')
|
63
|
+
end
|
64
|
+
end
|
data/lib/ramaze/helper.rb
CHANGED
@@ -1,22 +1,12 @@
|
|
1
1
|
# Copyright (c) 2009 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
|
-
|
5
|
-
module Helper
|
6
|
-
EXPOSE = LOOKUP = Innate::Helper::EXPOSE
|
7
|
-
|
8
|
-
def self.included(into)
|
9
|
-
into.extend(HelperAccess)
|
10
|
-
into.__send__(:include, Trinity)
|
11
|
-
end
|
4
|
+
require 'innate/helper'
|
12
5
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
17
|
-
end
|
6
|
+
module Ramaze
|
7
|
+
Helper = Innate::Helper
|
8
|
+
Innate::HelpersHelper.options.paths << File.dirname(__FILE__)
|
18
9
|
|
19
|
-
|
20
|
-
|
21
|
-
Innate::HelpersHelper.add_pool(Ramaze::Helper)
|
10
|
+
require 'ramaze/helper/flash'
|
11
|
+
require 'ramaze/helper/link'
|
22
12
|
end
|
@@ -83,7 +83,7 @@ module Ramaze
|
|
83
83
|
httpdigest_failure unless nonce == session_nonce and opaque == session_opaque
|
84
84
|
|
85
85
|
ha1 = httpdigest_lookup(username, realm, &block)
|
86
|
-
a2 = [request.request_method,request.
|
86
|
+
a2 = [request.request_method,request.request_uri]
|
87
87
|
a2 << Digest::MD5.hexdigest(request.body.read) if qop == "auth-int"
|
88
88
|
ha2 = Digest::MD5.hexdigest( a2.join(':') )
|
89
89
|
md5 = Digest::MD5.hexdigest([ha1, nonce, nc, cnonce, qop, ha2].join(':'))
|
data/lib/ramaze/helper/link.rb
CHANGED
@@ -5,13 +5,10 @@ require 'innate/helper/link'
|
|
5
5
|
|
6
6
|
module Ramaze
|
7
7
|
module Helper
|
8
|
+
# This is a modification of Innate::Helper::Link to respect the routing of
|
9
|
+
# Ramaze
|
8
10
|
# NOTE: The A/R/Rs methods have been deprecated.
|
9
11
|
module Link
|
10
|
-
include Innate::Helper::Link
|
11
|
-
|
12
|
-
def self.included(into)
|
13
|
-
into.extend(self)
|
14
|
-
end
|
15
12
|
|
16
13
|
# @return [String]
|
17
14
|
# @see Innate::Helper#anchor
|
@@ -1,24 +1,99 @@
|
|
1
|
-
|
1
|
+
# Copyright (c) 2009 Michael Fellinger m.fellinger@gmail.com
|
2
|
+
# All files in this distribution are subject to the terms of the Ruby license.
|
2
3
|
|
3
4
|
module Ramaze
|
4
5
|
module Helper
|
6
|
+
|
7
|
+
# = Helper::Partial
|
8
|
+
#
|
9
|
+
# Please note that this helper is deprecated in favor of # Helper::Render,
|
10
|
+
# it has been removed from Innate and remains in Ramaze until 2009.05.
|
11
|
+
#
|
12
|
+
# === Example Usage
|
13
|
+
#
|
14
|
+
# class MyController
|
15
|
+
# def index
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# def list
|
19
|
+
# plain = request['plain']
|
20
|
+
# "Hello World from List! Plain List == #{plain}"
|
21
|
+
# end
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
#
|
25
|
+
# <html>
|
26
|
+
# <head><title>Partial Render Index</title></head>
|
27
|
+
# <body>
|
28
|
+
# #{render_partial(Rs(:list), 'plain' => true)}
|
29
|
+
# </body>
|
30
|
+
# </html>
|
5
31
|
module Partial
|
6
|
-
|
32
|
+
module_function
|
33
|
+
|
34
|
+
# Renders a url 'inline'.
|
35
|
+
#
|
36
|
+
# +url+ normal URL, like you'd use for redirecting.
|
37
|
+
# +options+ optional, will be used as request parameters.
|
38
|
+
#
|
39
|
+
# Issues a mock request to the given +url+ with +options+ turned into
|
40
|
+
# query arguments.
|
41
|
+
def render_partial(url, options = {})
|
42
|
+
Ramaze.deprecated('Helper::Partial#render_partial', 'Helper::Render#render_full')
|
43
|
+
|
44
|
+
uri = URI(url)
|
45
|
+
query = options # Innate::Current.request.params.merge(options)
|
46
|
+
uri.query = Rack::Utils.build_query(query)
|
47
|
+
|
48
|
+
body = nil
|
49
|
+
|
50
|
+
Innate::Mock.session do |session|
|
51
|
+
cookie = Innate::Current.session.cookie
|
52
|
+
session.cookie = cookie
|
53
|
+
body = session.get(uri.to_s, options).body
|
54
|
+
end
|
7
55
|
|
8
|
-
|
9
|
-
into.extend(self)
|
10
|
-
into.extend(Innate::Helper::Partial)
|
56
|
+
body
|
11
57
|
end
|
12
58
|
|
13
|
-
|
14
|
-
|
59
|
+
# Render the template file in view_root of the
|
60
|
+
# current controller.
|
61
|
+
#
|
62
|
+
# TODO:
|
63
|
+
# * Doesn't work for absolute paths, but there are no specs for that yet.
|
64
|
+
# * the local variable hack isn't working because innate allocates a new
|
65
|
+
# binding.
|
66
|
+
# For now one can simply use instance variables, which I prefer anyway.
|
67
|
+
#
|
68
|
+
# the local binding hack:
|
69
|
+
#
|
70
|
+
# variables.each do |key, value|
|
71
|
+
# value = "ObjectSpace._id2ref(#{value.object_id})"
|
72
|
+
# eval "#{key} = #{value}", action.binding
|
73
|
+
# end
|
15
74
|
|
16
|
-
|
75
|
+
def render_template(path, variables = {})
|
76
|
+
Ramaze.deprecated('Helper::Partial#render_template')
|
77
|
+
path = path.to_s
|
78
|
+
|
79
|
+
ext = File.extname(path)
|
80
|
+
basename = File.basename(path, ext)
|
81
|
+
|
82
|
+
action = Innate::Current.action.dup
|
83
|
+
action.layout = nil
|
84
|
+
action.view = action.node.find_view(basename, 'html')
|
85
|
+
action.method = action.node.find_method(basename, action.params)
|
17
86
|
|
18
|
-
action.instance = action.node.new
|
19
87
|
action.variables = action.variables.merge(variables)
|
88
|
+
action.sync_variables(action)
|
89
|
+
|
90
|
+
return action.call if action.valid?
|
91
|
+
raise(ArgumentError, "cannot render %p" % path)
|
92
|
+
end
|
20
93
|
|
21
|
-
|
94
|
+
def render_action(method, *params)
|
95
|
+
Ramaze.deprecated('Helper::Partial#render_action', 'Helper::Render#render_full')
|
96
|
+
render_partial(r(method), *params)
|
22
97
|
end
|
23
98
|
end
|
24
99
|
end
|
data/lib/ramaze/request.rb
CHANGED
@@ -93,5 +93,25 @@ module Ramaze
|
|
93
93
|
env.reject{|key, value| key.to_s !~ INTERESTING_HTTP_VARIABLES }
|
94
94
|
end
|
95
95
|
alias http_vars http_variables
|
96
|
+
|
97
|
+
REQUEST_STRING_FORMAT = "#<%s params=%p cookies=%p env=%p>"
|
98
|
+
|
99
|
+
def to_s
|
100
|
+
REQUEST_STRING_FORMAT % [self.class, params, cookies, http_variables]
|
101
|
+
end
|
102
|
+
alias inspect to_s
|
103
|
+
|
104
|
+
# Pretty prints current action with parameters, cookies and enviroment
|
105
|
+
# variables.
|
106
|
+
def pretty_print(pp)
|
107
|
+
pp.object_group(self){
|
108
|
+
group = { 'params' => params, 'cookies' => cookies, 'env' => http_variables }
|
109
|
+
group.each do |name, hash|
|
110
|
+
pp.breakable
|
111
|
+
pp.text " @#{name}="
|
112
|
+
pp.nest(name.size + 3){ pp.pp_hash(hash) }
|
113
|
+
end
|
114
|
+
}
|
115
|
+
end
|
96
116
|
end
|
97
117
|
end
|
data/lib/ramaze/spec.rb
CHANGED
@@ -0,0 +1,48 @@
|
|
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 'ramaze/tool/project_creator'
|
5
|
+
|
6
|
+
module Ramaze
|
7
|
+
module Tool
|
8
|
+
|
9
|
+
# Create is a simple class used to create new projects based on the proto
|
10
|
+
# directory.
|
11
|
+
#
|
12
|
+
# It is primarly used for this command:
|
13
|
+
#
|
14
|
+
# ramaze --create project
|
15
|
+
#
|
16
|
+
# where project is the directory you want the content put into.
|
17
|
+
|
18
|
+
class Create
|
19
|
+
|
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(ROOT, '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
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,111 @@
|
|
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 = []
|
9
|
+
PROTO << '~/.proto/' if ENV["HOME"] # Guard against Windows
|
10
|
+
attr_accessor :name, :options
|
11
|
+
|
12
|
+
def initialize(name, options = {})
|
13
|
+
@name, @options = name, options
|
14
|
+
end
|
15
|
+
|
16
|
+
def target
|
17
|
+
File.expand_path(name)
|
18
|
+
end
|
19
|
+
|
20
|
+
def proto
|
21
|
+
PROTO.map!{|pr| File.expand_path(pr) }
|
22
|
+
proto = options[:proto] ||= PROTO.find{|f| File.directory?(f) }
|
23
|
+
layout = options[:layout] ||= '/'
|
24
|
+
File.expand_path(File.join(proto, layout))
|
25
|
+
end
|
26
|
+
|
27
|
+
def create_root?
|
28
|
+
return true unless File.directory?(target)
|
29
|
+
return true if amend? or force?
|
30
|
+
fatal "%p is a directory, choose different project name or use --amend/--force" % target
|
31
|
+
end
|
32
|
+
|
33
|
+
def got_proto?
|
34
|
+
return true if File.directory?(proto)
|
35
|
+
fatal "Cannot create, %p doesn't exist, use --proto or create the proto directory" % proto
|
36
|
+
end
|
37
|
+
|
38
|
+
def create
|
39
|
+
got_proto?
|
40
|
+
|
41
|
+
puts "Found proto at: %p, proceeding...\n\n" % proto
|
42
|
+
mkdir(relate('/')) if create_root?
|
43
|
+
proceed
|
44
|
+
end
|
45
|
+
|
46
|
+
def proceed
|
47
|
+
files, directories = partition{|path| File.file?(path) }
|
48
|
+
proceed_directories(directories)
|
49
|
+
proceed_files(files)
|
50
|
+
end
|
51
|
+
|
52
|
+
def proceed_files(files)
|
53
|
+
files.each{|file| copy(file, relate(file)) }
|
54
|
+
end
|
55
|
+
|
56
|
+
def proceed_directories(dirs)
|
57
|
+
dirs.each{|dir| mkdir(relate(dir)) }
|
58
|
+
end
|
59
|
+
|
60
|
+
def mkdir(dir)
|
61
|
+
exists = File.directory?(dir)
|
62
|
+
return if exists and amend?
|
63
|
+
return if exists and not force?
|
64
|
+
puts "mkdir(%p)" % dir
|
65
|
+
FileUtils.mkdir_p(dir)
|
66
|
+
end
|
67
|
+
|
68
|
+
def copy(from, to)
|
69
|
+
return unless copy_check(to)
|
70
|
+
puts "copy(%p, %p)" % [from, to]
|
71
|
+
FileUtils.cp(from, to)
|
72
|
+
post_process(to)
|
73
|
+
end
|
74
|
+
|
75
|
+
def copy_check(to)
|
76
|
+
exists = File.file?(to)
|
77
|
+
return if exists and amend?
|
78
|
+
return if exists and not force?
|
79
|
+
return true
|
80
|
+
end
|
81
|
+
|
82
|
+
# Think about a useful way to process the generated files it should be
|
83
|
+
# possible to substitute some things like the project name in the
|
84
|
+
# configuration
|
85
|
+
|
86
|
+
def post_process(file)
|
87
|
+
return
|
88
|
+
source = File.read(file)
|
89
|
+
File.open(file, 'w+') do |io|
|
90
|
+
io.write(source.gsub('$project', "'#@name'"))
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def relate(path)
|
95
|
+
File.join(target, path.to_s.sub(proto, ''))
|
96
|
+
end
|
97
|
+
|
98
|
+
def amend?; options[:amend] end
|
99
|
+
def force?; options[:force] end
|
100
|
+
|
101
|
+
def fatal(message)
|
102
|
+
warn message
|
103
|
+
exit 1
|
104
|
+
end
|
105
|
+
|
106
|
+
def each
|
107
|
+
Dir["#{proto}/**/*"].each{|path| yield(path) }
|
108
|
+
end
|
109
|
+
|
110
|
+
include Enumerable
|
111
|
+
end
|