ramaze 2012.04.14 → 2012.12.08b

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. data/.gems +28 -35
  2. data/.gitignore +4 -0
  3. data/.travis.yml +3 -3
  4. data/Gemfile +3 -0
  5. data/README.md +1 -5
  6. data/Rakefile +9 -20
  7. data/examples/app/blog/app.rb +5 -14
  8. data/examples/app/todolist/start.rb +1 -5
  9. data/guide/AUTHORS +8 -3
  10. data/guide/CHANGELOG +587 -0
  11. data/guide/general/cache.md +1 -0
  12. data/guide/general/configuration.md +2 -1
  13. data/guide/general/contributing.md +1 -0
  14. data/guide/general/controllers.md +105 -10
  15. data/guide/general/helpers.md +6 -7
  16. data/guide/general/installation.md +2 -1
  17. data/guide/general/logging.md +1 -4
  18. data/guide/general/middlewares.md +15 -23
  19. data/guide/general/models.md +1 -0
  20. data/guide/general/principles.md +1 -0
  21. data/guide/general/ramaze_command.md +9 -54
  22. data/guide/general/routes.md +1 -0
  23. data/guide/general/sessions.md +3 -2
  24. data/guide/general/special_thanks.md +1 -0
  25. data/guide/general/testing.md +1 -0
  26. data/guide/general/views.md +35 -22
  27. data/lib/proto/Gemfile +4 -0
  28. data/lib/proto/README.md +35 -0
  29. data/lib/proto/Rakefile +1 -0
  30. data/lib/proto/app.rb +2 -6
  31. data/lib/proto/spec/helper.rb +39 -0
  32. data/lib/proto/task/ramaze.rake +57 -0
  33. data/lib/ramaze.rb +12 -39
  34. data/lib/ramaze/bin/create.rb +1 -3
  35. data/lib/ramaze/bin/runner.rb +0 -14
  36. data/lib/ramaze/cache.rb +21 -0
  37. data/lib/ramaze/cache/memcache.rb +1 -3
  38. data/lib/ramaze/cache/redis.rb +2 -4
  39. data/lib/ramaze/cache/sequel.rb +4 -5
  40. data/lib/ramaze/controller.rb +10 -3
  41. data/lib/ramaze/default_middleware.rb +24 -0
  42. data/lib/ramaze/files.rb +5 -5
  43. data/lib/ramaze/gestalt.rb +10 -10
  44. data/lib/ramaze/helper/blue_form.rb +33 -6
  45. data/lib/ramaze/helper/csrf.rb +22 -30
  46. data/lib/ramaze/helper/flash.rb +1 -1
  47. data/lib/ramaze/helper/upload.rb +5 -3
  48. data/lib/ramaze/helper/user.rb +1 -0
  49. data/lib/ramaze/log.rb +0 -5
  50. data/lib/ramaze/log/informer.rb +3 -3
  51. data/lib/ramaze/log/logging.rb +4 -4
  52. data/lib/ramaze/log/syslog.rb +2 -2
  53. data/lib/ramaze/response.rb +1 -1
  54. data/lib/ramaze/snippets.rb +0 -20
  55. data/lib/ramaze/spec/bacon.rb +5 -13
  56. data/lib/ramaze/version.rb +1 -1
  57. data/lib/ramaze/view/erector.rb +1 -3
  58. data/lib/ramaze/view/erubis.rb +1 -3
  59. data/lib/ramaze/view/ezamar.rb +1 -3
  60. data/lib/ramaze/view/haml.rb +1 -4
  61. data/lib/ramaze/view/liquid.rb +1 -3
  62. data/lib/ramaze/view/lokar.rb +1 -3
  63. data/lib/ramaze/view/mustache.rb +1 -3
  64. data/lib/ramaze/view/nagoro.rb +1 -4
  65. data/lib/ramaze/view/remarkably.rb +1 -4
  66. data/lib/ramaze/view/sass.rb +2 -5
  67. data/lib/ramaze/view/slim.rb +1 -3
  68. data/lib/ramaze/view/slippers.rb +1 -3
  69. data/lib/ramaze/view/tagz.rb +1 -3
  70. data/lib/ramaze/view/tenjin.rb +1 -3
  71. data/ramaze.gemspec +45 -16
  72. data/spec/helper.rb +0 -1
  73. data/spec/ramaze/cache/localmemcache.rb +0 -4
  74. data/spec/ramaze/controller/mapping.rb +17 -0
  75. data/spec/ramaze/dispatcher/directory.rb +6 -5
  76. data/spec/ramaze/dispatcher/file.rb +7 -4
  77. data/spec/ramaze/files.rb +0 -2
  78. data/spec/ramaze/helper/csrf.rb +0 -26
  79. data/spec/ramaze/helper/upload.rb +1 -0
  80. data/spec/ramaze/helper/user.rb +12 -0
  81. data/spec/ramaze/log/syslog.rb +5 -1
  82. data/spec/ramaze/view/lokar.rb +1 -1
  83. data/spec/ramaze/view/nagoro.rb +1 -1
  84. data/tasks/bacon.rake +1 -1
  85. data/tasks/gems.rake +15 -0
  86. data/tasks/release.rake +37 -8
  87. metadata +106 -139
  88. data/guide/_static/ramaze_console.png +0 -0
  89. data/guide/tutorials/introduction.md +0 -263
  90. data/lib/proto/model/init.rb +0 -6
  91. data/lib/proto/public/.htaccess +0 -24
  92. data/lib/proto/public/dispatch.fcgi +0 -11
  93. data/lib/proto/spec/main.rb +0 -20
  94. data/lib/proto/start.rb +0 -20
  95. data/lib/ramaze/app_graph.rb +0 -105
  96. data/lib/ramaze/bin/console.rb +0 -87
  97. data/lib/ramaze/bin/helper.rb +0 -107
  98. data/lib/ramaze/bin/restart.rb +0 -95
  99. data/lib/ramaze/bin/start.rb +0 -221
  100. data/lib/ramaze/bin/status.rb +0 -152
  101. data/lib/ramaze/bin/stop.rb +0 -112
  102. data/lib/ramaze/dependencies.rb +0 -84
  103. data/lib/ramaze/helper/disqus.rb +0 -27
  104. data/lib/ramaze/helper/ultraviolet.rb +0 -49
  105. data/lib/ramaze/log/analogger.rb +0 -50
  106. data/lib/ramaze/log/growl.rb +0 -55
  107. data/lib/ramaze/log/knotify.rb +0 -31
  108. data/lib/ramaze/log/xosd.rb +0 -94
  109. data/lib/ramaze/middleware_compiler.rb +0 -36
  110. data/lib/ramaze/plugin.rb +0 -69
  111. data/lib/ramaze/setup.rb +0 -210
  112. data/lib/ramaze/snippets/array/put_within.rb +0 -38
  113. data/lib/ramaze/snippets/binding/locals.rb +0 -20
  114. data/lib/ramaze/snippets/fiber.rb +0 -41
  115. data/lib/ramaze/snippets/kernel/pretty_inspect.rb +0 -18
  116. data/lib/ramaze/snippets/metaid.rb +0 -17
  117. data/lib/ramaze/snippets/numeric/filesize_format.rb +0 -30
  118. data/lib/ramaze/snippets/numeric/time.rb +0 -59
  119. data/lib/ramaze/snippets/object/instance_variable_defined.rb +0 -16
  120. data/lib/ramaze/snippets/object/pretty.rb +0 -12
  121. data/lib/ramaze/snippets/object/scope.rb +0 -16
  122. data/lib/ramaze/snippets/ordered_set.rb +0 -51
  123. data/lib/ramaze/snippets/proc/locals.rb +0 -19
  124. data/lib/ramaze/snippets/ramaze/acquire.rb +0 -32
  125. data/lib/ramaze/snippets/ramaze/dictionary.rb +0 -400
  126. data/lib/ramaze/snippets/ramaze/fiber.rb +0 -24
  127. data/lib/ramaze/snippets/ramaze/struct.rb +0 -43
  128. data/lib/ramaze/snippets/string/end_with.rb +0 -17
  129. data/lib/ramaze/snippets/string/ord.rb +0 -16
  130. data/lib/ramaze/snippets/string/start_with.rb +0 -14
  131. data/lib/ramaze/snippets/thread/into.rb +0 -16
  132. data/lib/ramaze/spec.rb +0 -4
  133. data/spec/ramaze/bin/start.rb +0 -34
  134. data/spec/ramaze/log/growl.rb +0 -45
  135. data/spec/ramaze/struct.rb +0 -50
  136. data/spec/snippets/array/put_within.rb +0 -38
  137. data/spec/snippets/binding/locals.rb +0 -12
  138. data/spec/snippets/numeric/filesize_format.rb +0 -15
  139. data/spec/snippets/numeric/time.rb +0 -15
  140. data/spec/snippets/ordered_set.rb +0 -66
  141. data/spec/snippets/ramaze/acquire.rb +0 -80
  142. data/spec/snippets/ramaze/dictionary.rb +0 -113
  143. data/spec/snippets/ramaze/struct.rb +0 -15
  144. data/spec/snippets/thread/into.rb +0 -12
  145. data/tasks/gem.rake +0 -21
  146. data/tasks/setup.rake +0 -14
@@ -1,87 +0,0 @@
1
- require 'irb'
2
- require 'irb/completion'
3
-
4
- module Ramaze
5
- #:nodoc:
6
- module Bin
7
- ##
8
- # Allows the user to enter an IRB like session that takes advantage of
9
- # everything provided by Ramaze.
10
- #
11
- # Usage:
12
- #
13
- # ramaze console
14
- # ramaze console /path/to/app/start.rb
15
- #
16
- # @author Yorick Peterse
17
- # @since 21-07-2011
18
- #
19
- class Console
20
- # String containing the description of this command.
21
- Description = 'Starts an IRB session with Ramaze loaded into the session'
22
-
23
- # The banner that is displayed when the -h or --help option is specified.
24
- Banner = <<-TXT.strip
25
- Starts an IRB session and loads Ramaze into the session. All specified Rack
26
- options are ignored and environment variables are passed to IRB.
27
-
28
- Usage:
29
- ramaze console [DIR] [OPTIONS]
30
-
31
- Example:
32
- ramaze console
33
- ramaze console /home/foobar/ramaze/start.rb
34
- TXT
35
-
36
- ##
37
- # Creates a new instance of the command and sets all the options.
38
- #
39
- # @author Yorick Peterse
40
- # @since 21-07-2011
41
- #
42
- def initialize
43
- @options = OptionParser.new do |opt|
44
- opt.banner = Banner
45
- opt.summary_indent = ' '
46
-
47
- opt.separator "\nOptions:\n"
48
-
49
- opt.on('-h', '--help', 'Shows this help message') do
50
- puts @options
51
- exit
52
- end
53
- end
54
- end
55
-
56
- ##
57
- # Runs the command based on the given command line arguments.
58
- #
59
- # @author Yorick Peterse
60
- # @since 21-07-2011
61
- # @param [Array] argv An array of command line arguments.
62
- #
63
- def run(argv = [])
64
- @options.parse!(argv)
65
-
66
- start_file = argv.delete_at(0)
67
- start_file = File.join(Dir.pwd, 'start.rb') if start_file.nil?
68
-
69
- if File.directory?(start_file)
70
- start_file = File.join(start_file, 'start.rb')
71
- end
72
-
73
- if !File.exist?(start_file)
74
- abort "The file #{start_file} does not exist"
75
- end
76
-
77
- start_file = Pathname.new(start_file).realpath.to_s
78
- Ramaze.options.started = true
79
-
80
- require(start_file)
81
-
82
- IRB.start
83
- puts 'Ramazement has ended, go in peace.'
84
- end
85
- end # Console
86
- end # Bin
87
- end # Ramaze
@@ -1,107 +0,0 @@
1
- module Ramaze
2
- #:nodoc:
3
- module Bin
4
- ##
5
- # Module containing various helper methods useful for most commands.
6
- #
7
- # @author Yorick Peterse
8
- # @author TJ Vanderpoel
9
- # @since 21-07-2011
10
- #
11
- module Helper
12
- ##
13
- # Checks if the specified PID points to a process that's already running.
14
- #
15
- # @author TJ Vanderpoel
16
- # @since 21-07-2011
17
- # @param [String] pid The path to the PID.
18
- # @return [TrueClass|FalseClass]
19
- #
20
- def is_running?(pid)
21
- return false if !File.exist?(pid)
22
-
23
- pid = File.read(pid).to_i
24
-
25
- if is_windows?
26
- wmi = WIN32OLE.connect("winmgmts://")
27
- processes, ours = wmi.ExecQuery(
28
- "select * from win32_process where ProcessId = #{pid}"
29
- ), []
30
-
31
- processes.each { |process| ours << process.Name }
32
-
33
- return ours.first.nil?
34
- else
35
- begin
36
- prio = Process.getpriority(Process::PRIO_PROCESS, pid)
37
- return true
38
- rescue Errno::ESRCH
39
- return false
40
- end
41
- end
42
- end
43
-
44
- ##
45
- # Checks if the system the user is using is Windows.
46
- #
47
- # @author TJ Vanderpoel
48
- # @since 21-07-2011
49
- # @return [TrueClass|FalseClass]
50
- #
51
- def is_windows?
52
- return @is_win if @is_win
53
-
54
- begin; require "win32ole"; rescue LoadError; end
55
-
56
- @is_win ||= Object.const_defined?("WIN32OLE")
57
- end
58
-
59
- ##
60
- # Tries to extract the path to the Rackup executable.
61
- #
62
- # @author TJ Vanderpoel
63
- # @since 21-07-2001
64
- # @return [String]
65
- #
66
- def rackup_path
67
- return @rackup_path if @rackup_path
68
-
69
- # Check with 'which' on platforms which support it
70
- unless is_windows?
71
- @rackup_path = %x{which rackup}.to_s.chomp
72
-
73
- if @rackup_path.size > 0 and File.file?(@rackup_path)
74
- return @rackup_path
75
- end
76
- end
77
-
78
- # check for rackup in RUBYLIB
79
- libs = ENV["RUBYLIB"].to_s.split(is_windows? ? ";" : ":")
80
-
81
- if rack_lib = libs.detect { |r| r.match %r<(\\|/)rack\1> }
82
- require "pathname"
83
- @rackup_path = Pathname.new(rack_lib).parent.join("bin").join(
84
- "rackup"
85
- ).expand_path
86
-
87
- return @rackup_path if File.file?(@rackup_path)
88
- end
89
-
90
- begin
91
- require "rubygems"
92
- require "rack"
93
- require "pathname"
94
-
95
- @rackup_path = Pathname.new(Gem.bindir).join("rackup").to_s
96
-
97
- return @rackup_path if File.file?(@rackup_path)
98
- rescue LoadError
99
- nil
100
- end
101
-
102
- @rackup_path = nil
103
- abort "Cannot find the path to the Rackup executable"
104
- end
105
- end # Helper
106
- end # Bin
107
- end # Ramaze
@@ -1,95 +0,0 @@
1
- module Ramaze
2
- #:nodoc:
3
- module Bin
4
- ##
5
- # Restarts an application based on a specified directory/rackup file and
6
- # PID. The PID is used to kill the process, the Rackup file is used to start
7
- # the process again after it has been killed.
8
- #
9
- # Usage:
10
- #
11
- # ramaze restart
12
- # ramaze restart /home/foobar/projects/ramaze/ \
13
- # -P /home/foobar/projects/ramaze/ramaze.pid
14
- #
15
- # @author Yorick Peterse
16
- # @since 21-07-2011
17
- #
18
- class Restart
19
- # The description of this command, displayed in the global help message.
20
- Description = 'Restarts an application'
21
-
22
- # The banner, displayed when the -h or --help option is specified.
23
- Banner = <<-TXT.strip
24
- Restarts an active Ramaze application.
25
-
26
- Usage:
27
- ramaze restart [RACKUP] [OPTIONS]
28
-
29
- Example:
30
- ramaze restart config.ru -P ramaze.pid
31
- TXT
32
-
33
- ##
34
- # Creates a new instance of the command and sets all the options.
35
- #
36
- # @author Yorick Peterse
37
- # @since 21-07-2011
38
- #
39
- def initialize
40
- @options = OptionParser.new do |opt|
41
- opt.banner = Banner
42
- opt.summary_indent = ' '
43
-
44
- opt.separator "\nOptions:\n"
45
-
46
- opt.on('-h', '--help', 'Shows this help message') do
47
- puts @options
48
- exit
49
- end
50
-
51
- opt.on(
52
- '-P',
53
- '--pid FILE',
54
- 'Uses the PID to kill the application'
55
- ) do |pid|
56
- @pid = pid
57
- end
58
- end
59
- end
60
-
61
- ##
62
- # Runs the command based on the specified command line arguments.
63
- #
64
- # @author Yorick Peterse
65
- # @since 21-07-2011
66
- # @param [Array] argv An array containing all command line arguments.
67
- #
68
- def run(argv = [])
69
- @options.parse!(argv)
70
-
71
- @rackup = argv.delete_at(0)
72
- @rackup = File.join(Dir.pwd, 'config.ru') if @rackup.nil?
73
-
74
- if File.directory?(@rackup)
75
- @rackup = File.join(@rackup, 'config.ru')
76
- end
77
-
78
- if !File.exist?(@rackup)
79
- abort "The Rackup file #{@rackup} does not exist"
80
- end
81
-
82
- stop = Ramaze::Bin::Runner::Commands[:stop].new
83
- start = Ramaze::Bin::Runner::Commands[:start].new
84
- params = [@rackup]
85
-
86
- unless @pid.nil?
87
- params.push("-P #{@pid}")
88
- end
89
-
90
- stop.run([@pid])
91
- start.run(params)
92
- end
93
- end # Restart
94
- end # Bin
95
- end # Ramaze
@@ -1,221 +0,0 @@
1
- module Ramaze
2
- #:nodoc:
3
- module Bin
4
- ##
5
- # The start command is used to start a Ramaze application. The ramaze start
6
- # command optionally takes a directory or path to a file. If it's a
7
- # directory this command will look for a Rackup file in that directory,
8
- # otherwise it assumes the specified file is a Rackup file.
9
- #
10
- # Usage:
11
- #
12
- # ramaze start
13
- # ramaze start /home/foobar/projects/blog/config.ru
14
- # ramaze start /home/foobar/projects/blog
15
- #
16
- # @author Yorick Peterse
17
- # @since 21-07-2011
18
- #
19
- class Start
20
- include Ramaze::Bin::Helper
21
-
22
- # The description of this command, displayed when the global help menu is
23
- # invoked.
24
- Description = 'Starts an instance of an application'
25
-
26
- # The banner of this command, displayed when it's invoked with the -h or
27
- # --help option.
28
- Banner = <<-TXT.strip
29
- Starts an instance of an application using the settings
30
- specified in a Rackup file in the current directory.
31
-
32
- Usage:
33
- ramaze start [RACKUP CONFIG] [OPTIONS]
34
-
35
- Example:
36
- ramaze start --help
37
- TXT
38
-
39
- ##
40
- # Creates a new instance of the command and prepares OptionParser.
41
- #
42
- # @author Yorick Peterse
43
- # @since 21-07-2011
44
- #
45
- def initialize
46
- @ruby_options = {}
47
- @rack_options = {}
48
- @options = OptionParser.new do |opt|
49
- opt.banner = Banner
50
- opt.summary_indent = ' '
51
-
52
- # Sets all Ruby options
53
- opt.separator "\nRuby Options:\n"
54
-
55
- opt.on('-e', '--eval LINE', 'Evaluates a line of code') do |code|
56
- @ruby_options['-e'] = code
57
- end
58
-
59
- opt.on('-d', '--debug', 'Set debugging flags (set $DEBUG to true)') do
60
- @ruby_options['-d'] = nil
61
- end
62
-
63
- opt.on('-w', '--warn', 'Turns warnings on for the script') do
64
- @ruby_options['-w'] = nil
65
- end
66
-
67
- opt.on('-I', '--include PATH', 'specifies the $LOAD_PATH') do |path|
68
- @ruby_options['-I'] = path
69
- end
70
-
71
- opt.on(
72
- '-r',
73
- '--require LIBRARY',
74
- 'requires the library before starting'
75
- ) do |library|
76
- @ruby_options['-r'] = library
77
- end
78
-
79
- # Set all Rack options
80
- opt.separator "\nRack Options:\n"
81
-
82
- opt.on(
83
- '-s',
84
- '--server SERVER',
85
- 'Serve the application using the given server'
86
- ) do |server|
87
- @rack_options['-s'] = server
88
- end
89
-
90
- opt.on(
91
- '-o',
92
- '--host HOST',
93
- 'Listens on the given host (0.0.0.0 by default)'
94
- ) do |host|
95
- @rack_options['-o'] = host
96
- end
97
-
98
- opt.on(
99
- '-p',
100
- '--port PORT',
101
- 'Uses the given port, set to 9292 by default'
102
- ) do |port|
103
- @rack_options['-p'] = port
104
- end
105
-
106
- opt.on(
107
- '-O',
108
- '--option NAME[=VALUE]',
109
- 'Passes the given option and it\'s value to the server'
110
- ) do |name|
111
- @rack_options['-O'] = name
112
- end
113
-
114
- opt.on(
115
- '-E',
116
- '--env ENVIRONMENT',
117
- 'Uses the specified environment, set to development by default'
118
- ) do |env|
119
- @rack_options['-E'] = env
120
- end
121
-
122
- opt.on('-D', '--daemonize', 'Runs as a daemon in the background') do
123
- @rack_options['-D'] = nil
124
- end
125
-
126
- opt.on(
127
- '-P',
128
- '--pid FILE',
129
- 'File to store the PID in, defaults to rack.pid'
130
- ) do |pid|
131
- @rack_options['-P'] = pid
132
- end
133
-
134
- # Set all common options
135
- opt.separator "\nOptions\n"
136
-
137
- opt.on('-h', '--help', 'Shows this help message') do
138
- puts @options
139
- exit
140
- end
141
- end
142
- end
143
-
144
- ##
145
- # Runs the command based on the given command line arguments.
146
- #
147
- # @author Yorick Peterse
148
- # @since 21-07-2011
149
- # @param [Array] argv An array of command line arguments.
150
- #
151
- def run(argv = [])
152
- begin
153
- @options.parse!(argv)
154
- rescue => e
155
- warn "Error: #{e.message}"
156
- abort @options.to_s
157
- end
158
-
159
- # Remove all trailing/leading whitespace from the options
160
- @rack_options.each do |k, v|
161
- @rack_options[k] = v.strip if v.respond_to?(:strip)
162
- end
163
-
164
- @ruby_options.each do |k, v|
165
- @ruby_options[k] = v.strip if v.respond_to?(:strip)
166
- end
167
-
168
- rackup_config = argv.delete_at(0)
169
- rackup_config = File.join(Dir.pwd, 'config.ru') if rackup_config.nil?
170
-
171
- # Check if the config is a directory or file
172
- if File.directory?(rackup_config)
173
- rackup_config = File.join(rackup_config, 'config.ru')
174
- end
175
-
176
- if !File.exist?(rackup_config)
177
- abort "The Rackup config #{rackup_config} does not exist"
178
- end
179
-
180
- # Set the default port and server to use.
181
- if !@rack_options['-p']
182
- @rack_options['-p'] = 7000
183
- end
184
-
185
- # Set the default server to use
186
- if !@rack_options['-s']
187
- @rack_options['-s'] = Ramaze.options.adapter.handler.to_s
188
- end
189
-
190
- # If a PID is supplied we should first check to see if Ramaze isn't
191
- # already running.
192
- if @rack_options.key?('-P') and is_running?(@rack_options['-P'])
193
- abort 'This application is already running'
194
- end
195
-
196
- params = []
197
-
198
- @ruby_options.merge(@rack_options).each do |opt, value|
199
- params.push("#{opt}#{value}")
200
- end
201
-
202
- start_server(rackup_path, rackup_config, *params)
203
- end
204
-
205
- ##
206
- # Starts a server baed on the rackup path, rackup configuration file and
207
- # additional parameters.
208
- #
209
- # @author Yorick Peterse
210
- # @since 21-10-2011
211
- # @param [String] rackup_path The path to the Rackup executable.
212
- # @param [String] rackup_config The path to the config.ru file to use.
213
- # @param [Array] *params Additional parameters to pass to the ``exec()``
214
- # method.
215
- #
216
- def start_server(rackup_path, rackup_config, *params)
217
- exec('ruby', rackup_path, rackup_config, *params)
218
- end
219
- end # Start
220
- end # Bin
221
- end # Ramaze