ramaze 2009.10 → 2010.01
Sign up to get free protection for your applications and to get access to all the features.
- data/.mailmap +9 -7
- data/MANIFEST +13 -0
- data/Rakefile +35 -26
- data/benchmark/bench_templates/bench.rb +1 -1
- data/benchmark/bench_templates/view/large.lok +79 -0
- data/benchmark/bench_templates/view/small.lok +21 -0
- data/doc/AUTHORS +11 -9
- data/doc/CHANGELOG +138 -0
- data/examples/templates/template_markaby.rb +3 -3
- data/examples/templates/template_mustache.rb +70 -0
- data/examples/templates/view/external.mab +4 -4
- data/examples/templates/view/external.mt +29 -0
- data/lib/proto/start.rb +1 -1
- data/lib/ramaze/contrib/rest.rb +1 -0
- data/lib/ramaze/helper/form.rb +7 -1
- data/lib/ramaze/helper/httpdigest.rb +15 -16
- data/lib/ramaze/helper/xhtml.rb +5 -1
- data/lib/ramaze/snippets.rb +30 -7
- data/lib/ramaze/tool/project_creator.rb +20 -11
- data/lib/ramaze/version.rb +1 -1
- data/lib/ramaze/view.rb +3 -1
- data/lib/ramaze/view/haml.rb +6 -3
- data/lib/ramaze/view/lokar.rb +14 -0
- data/lib/ramaze/view/mustache.rb +40 -0
- data/lib/ramaze/view/slippers.rb +4 -2
- data/ramaze.gemspec +108 -81
- data/spec/examples/templates/template_mustache.rb +13 -0
- data/spec/ramaze/helper/form.rb +38 -37
- data/spec/ramaze/helper/httpdigest.rb +56 -29
- data/spec/ramaze/helper/xhtml.rb +2 -0
- data/spec/ramaze/view/lokar.rb +73 -0
- data/spec/ramaze/view/lokar/external.lok +8 -0
- data/spec/ramaze/view/lokar/sum.lok +1 -0
- data/spec/ramaze/view/mustache.rb +77 -0
- data/spec/ramaze/view/mustache/external.mt +8 -0
- data/spec/ramaze/view/mustache/sum.mt +1 -0
- data/tasks/authors.rake +0 -13
- metadata +144 -41
@@ -24,11 +24,11 @@ class MainController < Ramaze::Controller
|
|
24
24
|
p do
|
25
25
|
text "Here you can pass some stuff if you like, parameters are just passed like this:"
|
26
26
|
br
|
27
|
-
a("#@place/one", :href =>
|
27
|
+
a("#@place/one", :href => r(@this, @place, :one))
|
28
28
|
br
|
29
|
-
a("#@place/one/two/three", :href =>
|
29
|
+
a("#@place/one/two/three", :href => r(@this, @place, :one, :two, :three))
|
30
30
|
br
|
31
|
-
a("#@place/one?foo=bar", :href =>
|
31
|
+
a("#@place/one?foo=bar", :href => r(@this, @place, :one, :foo => :bar))
|
32
32
|
br
|
33
33
|
end
|
34
34
|
div do
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'ramaze'
|
3
|
+
|
4
|
+
class MainController < Ramaze::Controller
|
5
|
+
engine :Mustache
|
6
|
+
|
7
|
+
def index
|
8
|
+
@home = a('Home',:/)
|
9
|
+
@internal = a(:internal)
|
10
|
+
@external = a(:external)
|
11
|
+
|
12
|
+
%{ {{{home}}} | {{{internal}}} | {{{external}}} }
|
13
|
+
end
|
14
|
+
|
15
|
+
def internal(*args)
|
16
|
+
set_mustache_variables(:internal, *args)
|
17
|
+
|
18
|
+
%q{
|
19
|
+
<html>
|
20
|
+
<head>
|
21
|
+
<title>Template::Mustache external</title>
|
22
|
+
</head>
|
23
|
+
<body>
|
24
|
+
<h1>{{header}}</h1>
|
25
|
+
{{{link_home}}}
|
26
|
+
<p>
|
27
|
+
Here you can pass some stuff if you like, parameters are just passed like this:<br />
|
28
|
+
{{{link_one}}}<br />
|
29
|
+
{{{link_two}}}<br />
|
30
|
+
{{{link_three}}}
|
31
|
+
</p>
|
32
|
+
<div>
|
33
|
+
The arguments you have passed to this action are:
|
34
|
+
{{#args_empty}}
|
35
|
+
none
|
36
|
+
{{/args_empty}}
|
37
|
+
{{#not_empty}}
|
38
|
+
{{#args}}
|
39
|
+
<span>{{arg}}</span>
|
40
|
+
{{/args}}
|
41
|
+
{{/not_empty}}
|
42
|
+
</div>
|
43
|
+
<div>
|
44
|
+
{{params}}
|
45
|
+
</div>
|
46
|
+
</body>
|
47
|
+
</html>
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
def external *args
|
52
|
+
set_mustache_variables(:external, *args)
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def set_mustache_variables(place, *args)
|
58
|
+
@header = "The #{place} Template for Mustache"
|
59
|
+
@link_home = a('Home', :/)
|
60
|
+
@link_one = a("#{place}/one")
|
61
|
+
@link_two = a("#{place}/one/two/three")
|
62
|
+
@link_three = a("#{place}?foo=Bar")
|
63
|
+
@args = args.map { |arg| {:arg => arg} }
|
64
|
+
@args_empty = args.empty?
|
65
|
+
@not_empty = !@args_empty
|
66
|
+
@params = request.params.inspect
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
Ramaze.start :file => __FILE__
|
@@ -4,15 +4,15 @@ html do
|
|
4
4
|
end
|
5
5
|
body do
|
6
6
|
h1 "The #@place Template for Markaby"
|
7
|
-
a("Home", :href =>
|
7
|
+
a("Home", :href => r(@this))
|
8
8
|
p do
|
9
9
|
text "Here you can pass some stuff if you like, parameters are just passed like this:"
|
10
10
|
br
|
11
|
-
a("#@place/one", :href =>
|
11
|
+
a("#@place/one", :href => r(@this, @place, :one))
|
12
12
|
br
|
13
|
-
a("#@place/one/two/three", :href =>
|
13
|
+
a("#@place/one/two/three", :href => r(@this, @place, :one, :two, :three))
|
14
14
|
br
|
15
|
-
a("#@place/one?foo=bar", :href =>
|
15
|
+
a("#@place/one?foo=bar", :href => r(@this, @place, :one, :foo => :bar))
|
16
16
|
br
|
17
17
|
end
|
18
18
|
div do
|
@@ -0,0 +1,29 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<title>Template::Mustache external</title>
|
4
|
+
</head>
|
5
|
+
<body>
|
6
|
+
<h1>{{header}}</h1>
|
7
|
+
{{{link_home}}}
|
8
|
+
<p>
|
9
|
+
Here you can pass some stuff if you like, parameters are just passed like this:<br />
|
10
|
+
{{{link_one}}}<br />
|
11
|
+
{{{link_two}}}<br />
|
12
|
+
{{{link_three}}}
|
13
|
+
</p>
|
14
|
+
<div>
|
15
|
+
The arguments you have passed to this action are:
|
16
|
+
{{#args_empty}}
|
17
|
+
none
|
18
|
+
{{/args_empty}}
|
19
|
+
{{#not_empty}}
|
20
|
+
{{#args}}
|
21
|
+
<span>{{arg}}</span>
|
22
|
+
{{/args}}
|
23
|
+
{{/not_empty}}
|
24
|
+
</div>
|
25
|
+
<div>
|
26
|
+
{{params}}
|
27
|
+
</div>
|
28
|
+
</body>
|
29
|
+
</html>
|
data/lib/proto/start.rb
CHANGED
@@ -3,6 +3,6 @@
|
|
3
3
|
# All application related things should go into `app.rb`, this file is simply
|
4
4
|
# for options related to running the application locally.
|
5
5
|
|
6
|
-
require File.expand_path('app',
|
6
|
+
require File.expand_path('../app', __FILE__)
|
7
7
|
|
8
8
|
Ramaze.start(:adapter => :webrick, :port => 7000, :file => __FILE__)
|
data/lib/ramaze/contrib/rest.rb
CHANGED
data/lib/ramaze/helper/form.rb
CHANGED
@@ -13,6 +13,12 @@ module Ramaze
|
|
13
13
|
form_input(label, hash)
|
14
14
|
end
|
15
15
|
|
16
|
+
def form_checkbox_tag(label, name, value, checked = false)
|
17
|
+
hash = {:type => :checkbox, :name => name + '[]', :value => value}
|
18
|
+
hash[:checked] = 'checked' if checked
|
19
|
+
form_input(label, hash)
|
20
|
+
end
|
21
|
+
|
16
22
|
def form_password(label, name)
|
17
23
|
form_input(label, :type => :password, :name => name)
|
18
24
|
end
|
@@ -92,7 +98,7 @@ module Ramaze
|
|
92
98
|
Ramaze::Gestalt.build do
|
93
99
|
tr do
|
94
100
|
td do
|
95
|
-
label(:for => form_id){ "#{label}:" }
|
101
|
+
label(:for => form_id){ "#{label}:" } unless label==''
|
96
102
|
span(:class => "error"){ error } if error
|
97
103
|
end
|
98
104
|
td do
|
@@ -28,14 +28,14 @@ module Ramaze
|
|
28
28
|
::SecureRandom.hex(32)
|
29
29
|
end
|
30
30
|
|
31
|
-
|
32
|
-
#
|
33
|
-
# @param [String] uid
|
34
|
-
# @param [String] realm
|
35
|
-
def httpdigest_headers(uid, realm)
|
31
|
+
def httpdigest_failure_internal(uid,realm)
|
36
32
|
nonce = session[SESSION_NONCE] = httpdigest_uuid
|
37
33
|
opaque = session[SESSION_OPAQUE][realm][uid] = httpdigest_uuid
|
38
34
|
response['WWW-Authenticate'] = DIGEST_HEADER % [realm, nonce, opaque]
|
35
|
+
response['Pragma'] = 'no-cache' # HTTP/1.0
|
36
|
+
response['Cache-Control'] = 'no-cache' # HTTP/1.1
|
37
|
+
response['Last-Modified'] = Time.now.httpdate
|
38
|
+
httpdigest_failure
|
39
39
|
end
|
40
40
|
|
41
41
|
def httpdigest_failure
|
@@ -46,8 +46,7 @@ module Ramaze
|
|
46
46
|
http_authorization = request.env['HTTP_AUTHORIZATION']
|
47
47
|
return http_authorization if http_authorization
|
48
48
|
|
49
|
-
|
50
|
-
httpdigest_failure
|
49
|
+
httpdigest_failure_internal(uid, realm)
|
51
50
|
end
|
52
51
|
|
53
52
|
def httpdigest_lookup(username, realm)
|
@@ -69,26 +68,26 @@ module Ramaze
|
|
69
68
|
|
70
69
|
http_authorization = httpdigest_http_authorization(uid, realm)
|
71
70
|
|
72
|
-
|
73
|
-
|
71
|
+
httpdigest_failure_internal(uid, realm) unless session_nonce = session[SESSION_NONCE]
|
72
|
+
httpdigest_failure_internal(uid, realm) unless session_opaque = session[SESSION_OPAQUE][realm][uid]
|
74
73
|
|
75
74
|
auth_type, auth_raw = http_authorization.split(' ', 2)
|
76
|
-
|
75
|
+
httpdigest_failure_internal(uid, realm) unless auth_type == 'Digest'
|
77
76
|
|
78
77
|
authorization = Rack::Auth::Digest::Params.parse(auth_raw)
|
79
78
|
|
80
|
-
digest_response, username, nonce, nc, cnonce, qop, opaque =
|
81
|
-
authorization.values_at(*%w[response username nonce nc cnonce qop opaque])
|
79
|
+
digest_response, username, nonce, nc, cnonce, qop, opaque, uri =
|
80
|
+
authorization.values_at(*%w[response username nonce nc cnonce qop opaque uri])
|
82
81
|
|
83
|
-
|
82
|
+
httpdigest_failure_internal(uid, realm) unless nonce == session_nonce and opaque == session_opaque
|
84
83
|
|
85
84
|
ha1 = httpdigest_lookup(username, realm, &block)
|
86
|
-
a2 = [request.request_method,
|
85
|
+
a2 = [request.request_method,uri]
|
87
86
|
a2 << Digest::MD5.hexdigest(request.body.read) if qop == "auth-int"
|
88
|
-
ha2 = Digest::MD5.hexdigest(
|
87
|
+
ha2 = Digest::MD5.hexdigest(a2.join(':'))
|
89
88
|
md5 = Digest::MD5.hexdigest([ha1, nonce, nc, cnonce, qop, ha2].join(':'))
|
90
89
|
|
91
|
-
|
90
|
+
httpdigest_failure_internal(uid, realm) unless digest_response == md5
|
92
91
|
|
93
92
|
return username
|
94
93
|
end
|
data/lib/ramaze/helper/xhtml.rb
CHANGED
@@ -8,7 +8,11 @@ module Ramaze
|
|
8
8
|
|
9
9
|
def css(name, media = 'screen', options = {})
|
10
10
|
if options.empty?
|
11
|
-
|
11
|
+
if name =~ /^http/ # consider it external full url
|
12
|
+
LINK_TAG % [name, media]
|
13
|
+
else
|
14
|
+
LINK_TAG % ["/css/#{name}.css", media]
|
15
|
+
end
|
12
16
|
elsif options[:only].to_s.downcase == 'ie'
|
13
17
|
"<!--[if IE]>#{css(name, media)}<![endif]-->"
|
14
18
|
end
|
data/lib/ramaze/snippets.rb
CHANGED
@@ -1,12 +1,35 @@
|
|
1
|
-
# Copyright (c)
|
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
|
-
require '
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
require 'ramaze/snippets/array/put_within'
|
5
|
+
require 'ramaze/snippets/binding/locals'
|
6
|
+
require 'ramaze/snippets/blankslate'
|
7
|
+
require 'ramaze/snippets/fiber'
|
8
|
+
require 'ramaze/snippets/kernel/pretty_inspect'
|
9
|
+
require 'ramaze/snippets/metaid'
|
10
|
+
require 'ramaze/snippets/numeric/filesize_format'
|
11
|
+
require 'ramaze/snippets/numeric/time'
|
12
|
+
require 'ramaze/snippets/object/__dir__'
|
13
|
+
require 'ramaze/snippets/object/instance_variable_defined'
|
14
|
+
require 'ramaze/snippets/object/pretty'
|
15
|
+
require 'ramaze/snippets/object/scope'
|
16
|
+
require 'ramaze/snippets/ordered_set'
|
17
|
+
require 'ramaze/snippets/proc/locals'
|
18
|
+
require 'ramaze/snippets/ramaze/acquire'
|
19
|
+
require 'ramaze/snippets/ramaze/deprecated'
|
20
|
+
require 'ramaze/snippets/ramaze/dictionary'
|
21
|
+
require 'ramaze/snippets/ramaze/fiber'
|
22
|
+
require 'ramaze/snippets/ramaze/lru_hash'
|
23
|
+
require 'ramaze/snippets/ramaze/struct'
|
24
|
+
require 'ramaze/snippets/string/camel_case'
|
25
|
+
require 'ramaze/snippets/string/color'
|
26
|
+
require 'ramaze/snippets/string/end_with'
|
27
|
+
require 'ramaze/snippets/string/esc'
|
28
|
+
require 'ramaze/snippets/string/ord'
|
29
|
+
require 'ramaze/snippets/string/snake_case'
|
30
|
+
require 'ramaze/snippets/string/start_with'
|
31
|
+
require 'ramaze/snippets/string/unindent'
|
32
|
+
require 'ramaze/snippets/thread/into'
|
10
33
|
|
11
34
|
Ramaze::CoreExtensions.constants.each do |const|
|
12
35
|
ext = Ramaze::CoreExtensions.const_get(const)
|
@@ -58,25 +58,34 @@ class ProjectCreator
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def mkdir(dir)
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
puts
|
61
|
+
return unless mkdir?(dir)
|
62
|
+
|
63
|
+
relate = dir.sub("#{target}/", '')
|
64
|
+
puts "%12s %s" % ['mkdir', relate]
|
65
|
+
|
65
66
|
FileUtils.mkdir_p(dir)
|
66
67
|
end
|
67
68
|
|
69
|
+
def mkdir?(dir)
|
70
|
+
exists = File.directory?(dir)
|
71
|
+
|
72
|
+
!exists && amend? or exists && force? or !exists
|
73
|
+
end
|
74
|
+
|
68
75
|
def copy(from, to)
|
69
|
-
return unless
|
70
|
-
|
76
|
+
return unless copy?(to)
|
77
|
+
|
78
|
+
relate = to.sub("#{target}/", '')
|
79
|
+
puts "%12s %s" % ['create', relate]
|
80
|
+
|
71
81
|
FileUtils.cp(from, to, :preserve => true)
|
72
82
|
post_process(to)
|
73
83
|
end
|
74
84
|
|
75
|
-
def
|
76
|
-
exists = File.file?(
|
77
|
-
|
78
|
-
|
79
|
-
return true
|
85
|
+
def copy?(file)
|
86
|
+
exists = File.file?(file)
|
87
|
+
|
88
|
+
!exists && amend? or exists && force? or !exists
|
80
89
|
end
|
81
90
|
|
82
91
|
# Think about a useful way to process the generated files it should be
|
data/lib/ramaze/version.rb
CHANGED
data/lib/ramaze/view.rb
CHANGED
@@ -29,6 +29,7 @@ module Ramaze
|
|
29
29
|
auto_register :Haml, :haml
|
30
30
|
auto_register :Less, :lss, :less
|
31
31
|
auto_register :Liquid, :liquid
|
32
|
+
auto_register :Lokar, :lok
|
32
33
|
auto_register :Maruku, :mkd, :md
|
33
34
|
auto_register :Nagoro, :nag
|
34
35
|
auto_register :RedCloth, :redcloth
|
@@ -36,6 +37,7 @@ module Ramaze
|
|
36
37
|
auto_register :Sass, :sass
|
37
38
|
auto_register :Tagz, :rb, :tagz
|
38
39
|
auto_register :Tenjin, :rbhtml, :tenjin
|
39
|
-
auto_register :Slippers,
|
40
|
+
auto_register :Slippers, :st
|
41
|
+
auto_register :Mustache, :mt
|
40
42
|
end
|
41
43
|
end
|
data/lib/ramaze/view/haml.rb
CHANGED
@@ -10,10 +10,13 @@ module Ramaze
|
|
10
10
|
if haml_options = action.instance.ancestral_trait[:haml_options]
|
11
11
|
options = options.merge(haml_options)
|
12
12
|
end
|
13
|
-
|
13
|
+
action.sync_variables(action)
|
14
14
|
action.options[:filename] = (action.view || '(haml)')
|
15
|
-
|
16
|
-
|
15
|
+
|
16
|
+
haml = View.compile(string) do |s|
|
17
|
+
::Haml::Engine.new(s,options).render_proc(action.instance,*action.variables.keys)
|
18
|
+
end
|
19
|
+
html = haml.call action.variables
|
17
20
|
|
18
21
|
return html, 'text/html'
|
19
22
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'lokar'
|
2
|
+
|
3
|
+
module Ramaze
|
4
|
+
module View
|
5
|
+
module Lokar
|
6
|
+
def self.call(action, string)
|
7
|
+
compiled = View.compile(string){|s| ::Lokar.compile(s, action.view || __FILE__) }
|
8
|
+
html = action.instance.instance_eval(&compiled).join
|
9
|
+
|
10
|
+
return html, 'text/html'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'mustache'
|
2
|
+
|
3
|
+
module Ramaze
|
4
|
+
module View
|
5
|
+
# Binding to Mustache templating engine.
|
6
|
+
#
|
7
|
+
# Mustache uses user-defined class for rendering. Ramaze overwrites value,
|
8
|
+
# if controller defined same name variable as method that class defined.
|
9
|
+
#
|
10
|
+
# @see http://github.com/defunkt/mustache
|
11
|
+
module Mustache
|
12
|
+
def self.call(action, string)
|
13
|
+
context, path, ext = class_defined?(action)
|
14
|
+
|
15
|
+
action.sync_variables(action)
|
16
|
+
action.variables.each { |k, v| context[k.to_sym] = v }
|
17
|
+
|
18
|
+
view = View.compile(string) { |s| ::Mustache::Template.new(s, path, ext) }
|
19
|
+
html = view.render(context)
|
20
|
+
|
21
|
+
return html, 'text/html'
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.class_defined?(action)
|
25
|
+
return {}, nil, nil unless action.view
|
26
|
+
|
27
|
+
path = File.dirname(action.view)
|
28
|
+
|
29
|
+
klass = if FileTest.exist?(File.join(path, "#{action.name}.rb"))
|
30
|
+
require File.join(path, action.name)
|
31
|
+
::Object.const_get(::Mustache.classify(action.name)) # or eval?
|
32
|
+
else
|
33
|
+
::Mustache
|
34
|
+
end
|
35
|
+
|
36
|
+
return ::Mustache::Context.new(klass.new), path, View.exts_of(self).first
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/ramaze/view/slippers.rb
CHANGED
@@ -13,9 +13,11 @@ module Ramaze
|
|
13
13
|
private
|
14
14
|
def self.template_group(action)
|
15
15
|
subtemplates = action.instance.ancestral_trait[:slippers_options] || {}
|
16
|
+
missing_template_handler = action.instance.ancestral_trait[:slippers_missing_template_handler]
|
17
|
+
default_string = action.instance.ancestral_trait[:slippers_default_string]
|
16
18
|
views = action.instance.options[:views].map{|view| "#{action.instance.options[:roots]}/#{view}" }
|
17
|
-
super_group = ::Slippers::TemplateGroup.new(:templates => subtemplates)
|
18
|
-
::Slippers::TemplateGroupDirectory.new(views, :super_group => super_group)
|
19
|
+
super_group = ::Slippers::TemplateGroup.new(:templates => subtemplates, :missing_template_handler => missing_template_handler, :default_string => default_string)
|
20
|
+
::Slippers::TemplateGroupDirectory.new(views, :super_group => super_group, :missing_template_handler => missing_template_handler, :default_string => default_string)
|
19
21
|
end
|
20
22
|
end
|
21
23
|
end
|