manveru-ramaze 2008.08 → 2008.09

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. data/Rakefile +1 -1
  2. data/bin/ramaze +1 -0
  3. data/doc/CHANGELOG +966 -0
  4. data/doc/tutorial/todolist.html +421 -313
  5. data/doc/tutorial/todolist.mkd +26 -9
  6. data/examples/helpers/paginate.rb +71 -0
  7. data/examples/misc/simple_auth.rb +20 -8
  8. data/lib/proto/controller/init.rb +10 -0
  9. data/lib/proto/controller/main.rb +1 -3
  10. data/lib/proto/model/init.rb +4 -0
  11. data/lib/proto/spec/main.rb +2 -1
  12. data/lib/proto/start.rb +3 -3
  13. data/lib/ramaze.rb +6 -1
  14. data/lib/ramaze/action.rb +2 -2
  15. data/lib/ramaze/adapter.rb +0 -5
  16. data/lib/ramaze/adapter/base.rb +24 -7
  17. data/lib/ramaze/contrib/gzip_filter.rb +22 -9
  18. data/lib/ramaze/contrib/maruku_uv.rb +59 -0
  19. data/lib/ramaze/contrib/profiling.rb +1 -1
  20. data/lib/ramaze/contrib/sequel/create_join.rb +25 -0
  21. data/lib/ramaze/contrib/sequel/form_field.rb +129 -0
  22. data/lib/ramaze/contrib/sequel/image.rb +198 -0
  23. data/lib/ramaze/contrib/sequel/relation.rb +82 -0
  24. data/lib/ramaze/controller/resolve.rb +1 -1
  25. data/lib/ramaze/current.rb +60 -20
  26. data/lib/ramaze/current/response.rb +15 -3
  27. data/lib/ramaze/dispatcher.rb +9 -3
  28. data/lib/ramaze/dispatcher/action.rb +2 -3
  29. data/lib/ramaze/dispatcher/directory.rb +1 -1
  30. data/lib/ramaze/dispatcher/error.rb +1 -1
  31. data/lib/ramaze/dispatcher/file.rb +1 -1
  32. data/lib/ramaze/helper/formatting.rb +33 -0
  33. data/lib/ramaze/helper/paginate.rb +234 -0
  34. data/lib/ramaze/option.rb +2 -2
  35. data/lib/ramaze/reloader.rb +2 -2
  36. data/lib/ramaze/snippets.rb +13 -0
  37. data/lib/ramaze/snippets/array/put_within.rb +31 -24
  38. data/lib/ramaze/snippets/binding/locals.rb +23 -11
  39. data/lib/ramaze/snippets/kernel/constant.rb +36 -21
  40. data/lib/ramaze/snippets/kernel/pretty_inspect.rb +12 -6
  41. data/lib/ramaze/snippets/numeric/filesize_format.rb +24 -17
  42. data/lib/ramaze/snippets/numeric/time.rb +63 -56
  43. data/lib/ramaze/snippets/object/__dir__.rb +29 -0
  44. data/lib/ramaze/snippets/object/acquire.rb +40 -0
  45. data/lib/ramaze/snippets/object/instance_variable_defined.rb +16 -5
  46. data/lib/ramaze/snippets/object/pretty.rb +14 -4
  47. data/lib/ramaze/snippets/object/scope.rb +14 -7
  48. data/lib/ramaze/snippets/ordered_set.rb +4 -0
  49. data/lib/ramaze/snippets/proc/locals.rb +17 -9
  50. data/lib/ramaze/snippets/ramaze/struct.rb +45 -0
  51. data/lib/ramaze/snippets/string/camel_case.rb +13 -8
  52. data/lib/ramaze/snippets/string/color.rb +24 -20
  53. data/lib/ramaze/snippets/string/each.rb +14 -3
  54. data/lib/ramaze/snippets/string/end_with.rb +17 -6
  55. data/lib/ramaze/snippets/string/esc.rb +26 -18
  56. data/lib/ramaze/snippets/string/ord.rb +12 -6
  57. data/lib/ramaze/snippets/string/snake_case.rb +13 -7
  58. data/lib/ramaze/snippets/string/start_with.rb +16 -6
  59. data/lib/ramaze/snippets/string/unindent.rb +23 -15
  60. data/lib/ramaze/snippets/thread/into.rb +3 -3
  61. data/lib/ramaze/spec/helper/snippets.rb +8 -0
  62. data/lib/ramaze/template/ezamar/textpow.syntax +34 -0
  63. data/lib/ramaze/tool/create.rb +27 -53
  64. data/lib/ramaze/tool/project_creator.rb +110 -0
  65. data/lib/ramaze/version.rb +1 -1
  66. data/rake_tasks/gem.rake +2 -1
  67. data/rake_tasks/maintenance.rake +38 -0
  68. data/rake_tasks/release.rake +6 -2
  69. data/rake_tasks/spec.rake +1 -2
  70. data/ramaze.gemspec +69 -78
  71. data/spec/examples/simple_auth.rb +2 -2
  72. data/spec/examples/templates/template_haml.rb +0 -2
  73. data/spec/ramaze/current/session.rb +1 -1
  74. data/spec/ramaze/dispatcher/file.rb +2 -2
  75. data/spec/ramaze/helper/formatting.rb +13 -0
  76. data/spec/ramaze/rewrite.rb +1 -1
  77. data/spec/ramaze/struct.rb +47 -0
  78. data/spec/ramaze/template/markaby.rb +1 -1
  79. data/spec/snippets/{kernel → object}/__dir__.rb +0 -0
  80. data/spec/snippets/{kernel → object}/acquire.rb +0 -0
  81. metadata +69 -78
  82. data/examples/app/rammit/spec/rammit.rb +0 -31
  83. data/examples/app/rammit/src/controller/main.rb +0 -3
  84. data/examples/app/rammit/src/controller/page.rb +0 -16
  85. data/examples/app/rammit/src/model.rb +0 -33
  86. data/examples/app/rammit/start.rb +0 -8
  87. data/examples/app/rammit/template/index.xhtml +0 -14
  88. data/examples/app/rammit/template/page/view.xhtml +0 -4
  89. data/lib/ramaze/snippets/kernel/__dir__.rb +0 -23
  90. data/lib/ramaze/snippets/kernel/acquire.rb +0 -34
  91. data/lib/ramaze/snippets/struct/fill.rb +0 -23
  92. data/lib/ramaze/snippets/struct/values_at.rb +0 -39
  93. data/lib/ramaze/snippets/symbol/to_proc.rb +0 -24
  94. data/lib/ramaze/sourcereload.rb +0 -183
  95. data/spec/snippets/struct/fill.rb +0 -26
  96. data/spec/snippets/struct/values_at.rb +0 -52
  97. data/spec/snippets/symbol/to_proc.rb +0 -13
@@ -1,31 +0,0 @@
1
- require 'ramaze'
2
- require 'ramaze/spec/helper'
3
-
4
- $LOAD_PATH.unshift base = __DIR__/'..'
5
- spec_require 'hpricot', 'sequel'
6
-
7
- require 'start'
8
-
9
- describe 'Rammit' do
10
- behaves_like 'http'
11
- base = File.expand_path(__DIR__/'..')
12
- ramaze :view_root => base/'template',
13
- :public_root => base/'public'
14
-
15
- it 'should have intro page' do
16
- got = get('/')
17
- doc = Hpricot(got.body)
18
- form = doc.at(:form)
19
- form.at('textarea[@name=text]').should.not == nil
20
- form.at('input[@type=submit @value="Create a site"]').should.not == nil
21
- end
22
-
23
- it 'should create page from intro page' do
24
- got = post('/page/create', 'text' => 'Some text')
25
- refer = got.headers['Location']
26
- refer.should.not == nil
27
- got = get(refer)
28
- doc = Hpricot(got.body)
29
- doc.at('div#text').inner_html.should =~ /Some text/
30
- end
31
- end
@@ -1,3 +0,0 @@
1
- class MainController < Ramaze::Controller
2
- map '/'
3
- end
@@ -1,16 +0,0 @@
1
- class PageController < Ramaze::Controller
2
- map '/page'
3
-
4
- def create
5
- redirect_referrer unless request.post?
6
- if text = request[:text]
7
- page = Page.create :text => text
8
- redirect page.url
9
- end
10
- end
11
-
12
- def view(oid)
13
- page = Page[oid]
14
- @text = page.text
15
- end
16
- end
@@ -1,33 +0,0 @@
1
- require 'sequel'
2
-
3
- DB = Sequel.sqlite
4
-
5
- class User < Sequel::Model(:user)
6
- set_schema do
7
- primary_key :id
8
-
9
- text :nick
10
- text :password
11
- text :email
12
- time :created
13
- end
14
- end
15
-
16
- class Page < Sequel::Model(:page)
17
- include Ramaze::Helper::Link
18
-
19
- set_schema do
20
- primary_key :id
21
-
22
- text :text
23
- end
24
-
25
- def url
26
- R(PageController, :view, id)
27
- end
28
-
29
- end
30
-
31
- [ User, Page ].each do |model|
32
- model.create_table! unless model.table_exists?
33
- end
@@ -1,8 +0,0 @@
1
- require 'rubygems'
2
- require 'ramaze'
3
-
4
- require 'src/model'
5
- require 'src/controller/main'
6
- require 'src/controller/page'
7
-
8
- Ramaze.start
@@ -1,14 +0,0 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
- <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
4
- <head>
5
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6
- <title>Rammit</title>
7
- </head>
8
- <body>
9
- <form method="POST" action="#{R PageController, :create}">
10
- <textarea name="text"></textarea>
11
- <input type="submit" value="Create a site" />
12
- </form>
13
- </body>
14
- </html>
@@ -1,4 +0,0 @@
1
- <div id="text">
2
- #@text
3
- </div>
4
-
@@ -1,23 +0,0 @@
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
- # Extensions for Kernel
5
-
6
- module Kernel
7
- unless defined?__DIR__
8
-
9
- # This is similar to +__FILE__+ and +__LINE__+, and returns a String
10
- # representing the directory of the current file is.
11
- # Unlike +__FILE__+ the path returned is absolute.
12
- #
13
- # This method is convenience for the
14
- # File.expand_path(File.dirname(__FILE__))
15
- # idiom.
16
- #
17
-
18
- def __DIR__()
19
- filename = caller[0][/^(.*):/, 1]
20
- File.expand_path(File.dirname(filename))
21
- end
22
- end
23
- end
@@ -1,34 +0,0 @@
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
- # Extensions for Kernel
5
-
6
- module Kernel
7
-
8
- # Require all .rb and .so files on the given globs, utilizes Dir::[].
9
- #
10
- # Examples:
11
- # # Given following directory structure:
12
- # # src/foo.rb
13
- # # src/bar.so
14
- # # src/foo.yaml
15
- # # src/foobar/baz.rb
16
- # # src/foobar/README
17
- #
18
- # # requires all files in 'src':
19
- # acquire 'src/*'
20
- #
21
- # # requires all files in 'src' recursive:
22
- # acquire 'src/**/*'
23
- #
24
- # # require 'src/foo.rb' and 'src/bar.so' and 'src/foobar/baz.rb'
25
- # acquire 'src/*', 'src/foobar/*'
26
-
27
- def acquire *globs
28
- globs.flatten.each do |glob|
29
- Dir[glob].each do |file|
30
- require file if file =~ /\.(rb|so)$/
31
- end
32
- end
33
- end
34
- end
@@ -1,23 +0,0 @@
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
- # Extensions for Struct
5
-
6
- class Struct
7
-
8
- # Action = Struct.new('Action', :template, :method, :params)
9
- #
10
- # a = Action.fill(:template => nil, :method => :meth, :params => [1])
11
- # # => #<struct Struct::Action template=nil, method=:meth, params=[1]>
12
-
13
- def self.fill(hash = {})
14
- instance = new
15
- to_s = members.first.respond_to?(:to_str)
16
- hash.each do |key, value|
17
- key = to_s ? key.to_s : key.to_sym
18
- next unless members.include?(key)
19
- instance.send("#{key}=", value)
20
- end
21
- instance
22
- end
23
- end
@@ -1,39 +0,0 @@
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
- # Extensions for Struct
5
-
6
- class Struct
7
- undef values_at
8
-
9
- # Example:
10
- # Point = Struct.new(:x, :y)
11
- # point = Point.new(15, 10)
12
- # point.values_at(:y, :x)
13
- # # => [10, 15]
14
- # point.values_at(0, 1)
15
- # # => [15, 10]
16
- # point.values_at(0..1)
17
- # # => [15, 10]
18
-
19
- def values_at(*keys)
20
- if keys.all?{|key| key.respond_to?(:to_int) and not key.is_a?(Symbol) }
21
- keys.map{|key| values[key.to_int] }
22
- else
23
- out = []
24
-
25
- keys.each do |key|
26
- case key
27
- when Range
28
- key.each do |r|
29
- out << self[r]
30
- end
31
- else
32
- out << self[key]
33
- end
34
- end
35
-
36
- out
37
- end
38
- end
39
- end
@@ -1,24 +0,0 @@
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
- # Extensions for Symbol
5
-
6
- class Symbol
7
- unless method_defined?(:to_proc)
8
-
9
- # Turns the symbol into a simple proc, which is especially useful for enumerations. Examples:
10
- #
11
- # # The same as people.collect { |p| p.name }
12
- # people.collect(&:name)
13
- #
14
- # # The same as people.select { |p| p.manager? }.collect { |p| p.salary }
15
- # people.select(&:manager?).collect(&:salary)
16
- #
17
- # [1, 2, 3].map(&:to_s) # => ['1', '2', '3']
18
- # %w[a b c].map(&:to_sym) # => [:a, :b, :c]
19
-
20
- def to_proc
21
- Proc.new{|*args| args.shift.__send__(self, *args) }
22
- end
23
- end
24
- end
@@ -1,183 +0,0 @@
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
- module Ramaze
5
- Reloader::OPTIONS[:cooldown] = nil
6
-
7
- # SourceReload provides a way to reload changed files automatically during
8
- # runtime. Its default behaviour in Ramaze is to check periodically for
9
- # files with newer mtime and then attempts to load them in a controlled
10
- # manner.
11
-
12
- class SourceReload
13
-
14
- # Called from Ramaze::startup
15
- def self.startup(options = {})
16
- Thread.main[:sourcereload] = new
17
- end
18
-
19
- def self.restart
20
- return unless running?
21
- Log.dev("Restart SourceReload")
22
- shutdown
23
- startup
24
- end
25
-
26
- # Maybe make this better?
27
- def self.shutdown
28
- if running? and thread = Thread.main[:sourcereload].thread
29
- thread.kill
30
- end
31
- end
32
-
33
- def self.running?
34
- !Thread.main[:sourcereload].nil?
35
- end
36
-
37
- attr_reader :thread
38
- attr_accessor :interval
39
-
40
- # Setup the @mtimes hash. any new file will be assigned it's last modified
41
- # time (mtime) so we don't reload a file when we see it the first time.
42
- #
43
- # The thread only runs if Global.sourcereload is set.
44
- def initialize(interval = Global.sourcereload)
45
- if sr = Thread.main[:sourcereload]
46
- sr.interval = interval
47
- else
48
- @interval = interval
49
- startup
50
- end
51
- end
52
-
53
- def startup
54
- return unless @interval
55
- Log.debug("Startup SourceReload")
56
-
57
- @mtimes = Hash.new{|h,k| h[k] = mtime(k) }
58
-
59
- @thread = Thread.new{
60
- current = Thread.current
61
- current.priority = -1
62
-
63
- while iv = @interval
64
- rotate
65
- sleep iv
66
- end
67
- }
68
- end
69
-
70
- # One iteration of rotate will look for files that changed since the last
71
- # iteration and will try to #safe_load it.
72
- # This method is quite handy if you want direct control over when your
73
- # code is reloaded.
74
- #
75
- # Usage example:
76
- #
77
- # trap :HUP do
78
- # Ramaze::Log.info "reloading source"
79
- # Thread.main[:sourcereload].rotate
80
- # end
81
- #
82
-
83
- def rotate
84
- before_rotation
85
-
86
- rotation do |file|
87
- mtime = mtime(file)
88
-
89
- if mtime > @mtimes[file]
90
- safe_load(file)
91
- end
92
- end
93
-
94
- after_rotation
95
- end
96
-
97
- # Iterates over the $LOADED_FEATURES ($") and $LOAD_PATH ($:) and tries to
98
- # find either absolute paths or tries to find one by combining paths and files.
99
- # Every found file is yielded to the rotate method.
100
-
101
- def rotation
102
- files = Array[$0, *$LOADED_FEATURES].uniq
103
- paths = Array['./', *$LOAD_PATH].uniq
104
-
105
- files.each do |file|
106
- if Pathname.new(file).absolute?
107
- yield(file) if File.file?(file)
108
- else
109
- paths.each do |path|
110
- full = File.join(path, file)
111
- if File.file?(full)
112
- break yield(full)
113
- end
114
- end
115
- end
116
- end
117
- end
118
-
119
- # Safe mtime
120
- def mtime(file)
121
- File.mtime(file)
122
- rescue Errno::ENOENT
123
- false
124
- end
125
-
126
- # A safe Kernel::load, issuing the hooks depending on the results
127
- def safe_load(file)
128
- before_safe_load(file)
129
- load(file)
130
- after_safe_load_succeed(file)
131
- rescue Object => ex
132
- after_safe_load_failed(file, ex)
133
- ensure
134
- @mtimes[file] = mtime(file)
135
- end
136
- end
137
-
138
- # Holds hooks that are called before and after #reload and #safe_load
139
-
140
- module SourceReloadHooks
141
- # Overwrite to add actions before the reload rotation is started.
142
-
143
- def before_rotation
144
- end
145
-
146
- # Overwrite to add actions after the reload rotation has ended.
147
-
148
- def after_rotation
149
- end
150
-
151
- # Overwrite to add actions before a file is Kernel::load-ed
152
-
153
- def before_safe_load(file)
154
- Log.debug("reload #{file}")
155
- end
156
-
157
- # Overwrite to add actions after a file is Kernel::load-ed successfully,
158
- # by default we clean the Cache for compiled templates and resolved actions.
159
-
160
- def after_safe_load_succeed(file)
161
- Cache.compiled.clear
162
- Cache.resolved.clear
163
- Cache.action_methods.clear
164
- after_safe_load(file)
165
- end
166
-
167
- # Overwrite to add custom hook in addition to default Cache cleaning
168
-
169
- def after_safe_load(file)
170
- end
171
-
172
- # Overwrite to add actions after a file is Kernel::load-ed unsuccessfully,
173
- # by default we output an error-message with the exception.
174
-
175
- def after_safe_load_failed(file, error)
176
- Log.error(error)
177
- end
178
- end
179
-
180
- class SourceReload
181
- include SourceReloadHooks
182
- end
183
- end