mentawai 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.txt CHANGED
@@ -1,7 +1,10 @@
1
- == 0.5.0 2008-03-17
2
-
3
- * 3 major enhancement:
4
- * Using Rake instead of Merb
5
- * menta script to create blank app
6
- * Available as ruby gem 'mentawai'
1
+ == 0.6.0 2008-04-30
7
2
 
3
+ * MentaOnRuby is now a web container as well as a web server
4
+ * Now supports directory listing, default page, and static file serving like a web server
5
+ * No more /views or /actions directory. Now we have /WEB-INF/src and /WEB-INF/lib
6
+ * ERB pages can be anywere now
7
+ * Everything inside /WEB-INF directory is protected from external access
8
+ * You can run different applications in the same instance of MentaOnRuby ('/' = /ROOT directory like Java servlets)
9
+ * You can use the new page method content_type to set the content-type of a erb template (ex: text/xml)
10
+ * Many other improvements and bug fixes
data/Manifest.txt CHANGED
@@ -1,43 +1,50 @@
1
- History.txt
2
- License.txt
3
- Manifest.txt
4
- README.txt
5
- Rakefile
6
- bin/menta
7
- config/hoe.rb
8
- config/requirements.rb
9
- lib/mentawai.rb
10
- lib/mentawai/core/action.rb
11
- lib/mentawai/core/action_config.rb
12
- lib/mentawai/core/app_context.rb
13
- lib/mentawai/core/app_manager.rb
14
- lib/mentawai/core/controller.rb
15
- lib/mentawai/core/cookies.rb
16
- lib/mentawai/core/forward.rb
17
- lib/mentawai/core/input.rb
18
- lib/mentawai/core/invocation_chain.rb
19
- lib/mentawai/core/output.rb
20
- lib/mentawai/core/session.rb
21
- lib/mentawai/loader.rb
22
- lib/mentawai/page/methods/out.rb
23
- lib/mentawai/page/page_method.rb
24
- lib/mentawai/server.rb
25
- lib/mentawai/session/menta_session.rb
26
- lib/mentawai/session/rack_session.rb
27
- lib/mentawai/util/string.rb
28
- lib/mentawai/version.rb
29
- log/debug.log
30
- script/destroy
31
- script/generate
32
- script/txt2html
33
- setup.rb
34
- tasks/deployment.rake
35
- tasks/environment.rake
36
- tasks/website.rake
37
- test/test_helper.rb
38
- test/test_mentawai.rb
39
- website/index.html
40
- website/index.txt
41
- website/javascripts/rounded_corners_lite.inc.js
42
- website/stylesheets/screen.css
43
- website/template.rhtml
1
+ History.txt
2
+ License.txt
3
+ Manifest.txt
4
+ PostInstall.txt
5
+ README.txt
6
+ Rakefile
7
+ bin/menta
8
+ config/hoe.rb
9
+ config/requirements.rb
10
+ lib/mentawai.rb
11
+ lib/mentawai/application.rb
12
+ lib/mentawai/core/action.rb
13
+ lib/mentawai/core/action_config.rb
14
+ lib/mentawai/core/app_context.rb
15
+ lib/mentawai/core/app_manager.rb
16
+ lib/mentawai/core/controller.rb
17
+ lib/mentawai/core/cookies.rb
18
+ lib/mentawai/core/forward.rb
19
+ lib/mentawai/core/input.rb
20
+ lib/mentawai/core/invocation_chain.rb
21
+ lib/mentawai/core/output.rb
22
+ lib/mentawai/core/session.rb
23
+ lib/mentawai/handler/menta_handler.rb
24
+ lib/mentawai/i18n/loc_manager.rb
25
+ lib/mentawai/loader.rb
26
+ lib/mentawai/page/methods/content_type.rb
27
+ lib/mentawai/page/methods/messages.rb
28
+ lib/mentawai/page/methods/out.rb
29
+ lib/mentawai/page/page_method.rb
30
+ lib/mentawai/server.rb
31
+ lib/mentawai/session/menta_session.rb
32
+ lib/mentawai/session/rack_session.rb
33
+ lib/mentawai/util/array.rb
34
+ lib/mentawai/util/properties.rb
35
+ lib/mentawai/util/string.rb
36
+ lib/mentawai/version.rb
37
+ script/console
38
+ script/console.cmd
39
+ script/destroy
40
+ script/destroy.cmd
41
+ script/generate
42
+ script/generate.cmd
43
+ script/txt2html
44
+ script/txt2html.cmd
45
+ setup.rb
46
+ tasks/deployment.rake
47
+ tasks/environment.rake
48
+ tasks/website.rake
49
+ test/test_helper.rb
50
+ test/test_mentawai.rb
data/bin/menta CHANGED
@@ -1,122 +1,244 @@
1
- #!/usr/bin/env ruby
2
-
3
- def version
4
- require 'mentawai/version'
5
- puts "mentawai #{Mentawai::VERSION::STRING}" +
6
- " - The Mentawai Web Framework implemented in Ruby"
7
- puts "More information on http://www.mentaframework.org"
8
- end
9
-
10
- def help
11
- version
12
- puts
13
- puts "-v,--version\t\tShow version"
14
- puts "-h,--help\t\tShow this help"
15
- puts "<appname>\t\tCreate blank menta app"
16
- end
17
-
18
- START_FILE = <<EOF
19
- require 'rubygems'
20
- require 'mentawai'
21
-
22
- server = Mentawai::Server.new
23
- server.host = '0.0.0.0'
24
- server.port = 8080
25
-
26
- # Setup the ROOT context (ROOT web application)
27
- server.application('/', 'app_manager.rb', 'AppManager')
28
-
29
- # You can setup as many applications as you want
30
- # Ex:
31
- # server.application('/myapp1', 'myapp1.rb', 'AppManager')
32
- # server.application('/myapp2', 'myapp2.rb', 'AppManager')
33
-
34
- # Start mongrel web server to server you mentawai app
35
- server.start
36
- EOF
37
-
38
- APP_MANAGER_FILE = <<EOF
39
- include Mentawai::Core
40
-
41
- class AppManager < ApplicationManager
42
-
43
- def init(appContext)
44
- action("Hello").on(:success => Forward.new("hello.erb"))
45
- addPageMethod(:m_my_method, 'Mentawai::Page::Method::Out', 'print')
46
- end
47
-
48
- end
49
- EOF
50
-
51
- ACTION_FILE = <<EOF
52
-
53
- class Hello < Mentawai::Core::Action
54
-
55
- def execute
56
-
57
- puts "Inside action Hello!"
58
-
59
- username = input['username']
60
-
61
- username = "NO USER" if username.nil?
62
-
63
- output['username'] = username.upcase
64
-
65
- :success
66
-
67
- end
68
- end
69
- EOF
70
-
71
- VIEW_FILE = <<EOF
72
- <html>
73
- <body>
74
- <!-- using menta method m_out -->
75
- <h3>Hello1: <%= m_out('username') %></h3>
76
- <!-- using custom page method -->
77
- <h3>Hello2: <%= m_my_method('username') %></h3>
78
- </body>
79
- </html>
80
- EOF
81
-
82
- def create_app(app)
83
- Dir.mkdir(app)
84
- Dir.mkdir(app + '/actions')
85
- Dir.mkdir(app + '/views')
86
- f = File.open(app + '/start.rb', 'w')
87
- f.print START_FILE
88
- f.close
89
- f = File.open(app + '/app_manager.rb', 'w')
90
- f.print APP_MANAGER_FILE
91
- f.close
92
- f = File.open(app + '/actions/hello.rb', 'w')
93
- f.print ACTION_FILE
94
- f.close
95
- f = File.open(app + '/views/hello.erb', 'w')
96
- f.print VIEW_FILE
97
- f.close
98
- puts "Create menta app \"#{app}\""
99
- puts "To run: ruby start.rb inside \"#{app}\""
100
- end
101
-
102
- if %w(-v --version).include? ARGV.first
103
- version
104
- exit(0)
105
- end
106
-
107
- if %w(-h --help).include?(ARGV.first) || ARGV.length == 0 then
108
- help
109
- exit(0)
110
- end
111
-
112
- if ARGV.length == 1
113
- arg = ARGV[0]
114
- if arg =~ /^\-\-?/
115
- puts "Unrecognized argument: #{arg}"
116
- exit(0)
117
- end
118
- create_app(arg)
119
- end
120
-
121
-
122
-
1
+ #!/usr/bin/env ruby
2
+
3
+ def version
4
+ require 'mentawai/version'
5
+ puts "mentawai #{Mentawai::VERSION::STRING}" +
6
+ " - Mentawai Web Container, Server and Framework in Ruby"
7
+ puts "More information on http://www.mentaframework.org"
8
+ end
9
+
10
+ def help
11
+ version
12
+ puts
13
+ puts "-v,--version\t\tShow version"
14
+ puts "-h,--help\t\tShow this help"
15
+ puts "-c,--create <dirname>\tCreate web container (default dirname = 'mentawai')"
16
+ end
17
+
18
+ START_FILE = <<EOF
19
+ require 'rubygems'
20
+ require 'mentawai'
21
+
22
+ include Mentawai
23
+
24
+ server = Server.new
25
+ server.host = '127.0.0.1'
26
+ server.port = 8081
27
+
28
+ # Configure the parameters of your web application... (ROOT context)
29
+
30
+ root_app_options = {
31
+ :app_context => '/', # default = '/'
32
+ :app_manager_file => 'app_manager.rb', # default = 'app_manager.rb'
33
+ :app_manager_class => 'AppManager', # default = 'AppManager'
34
+ :action_extension => 'mtw', # default = 'mtw'
35
+ :listing_allowed => false, # default = false
36
+ :default_page => 'index.erb', # default = 'index.erb'
37
+ :dirs_allowed_for_listing => [] # default = []
38
+ }
39
+
40
+ server.add(root_app_options)
41
+
42
+ # Configure the parameters of a second web application... (/myapp context)
43
+
44
+ myapp_app_options = {
45
+ :app_context => '/myapp',
46
+ :action_extension => 'menta',
47
+ :listing_allowed => true,
48
+ :dirs_allowed_for_listing => ['img']
49
+ }
50
+
51
+ server.add(myapp_app_options)
52
+
53
+ # Start mongrel server to serve your Mentawai applications...
54
+
55
+ server.start
56
+
57
+
58
+ EOF
59
+
60
+ APP_MANAGER_FILE_1 = <<EOF
61
+ include Mentawai::Core
62
+
63
+ class AppManager < ApplicationManager
64
+
65
+ def init(appContext)
66
+
67
+ # Define an action...
68
+ action(:action_name => "/Hello", :class_name => "MyApp1::Hello").on(:success => fwd("hello.erb"))
69
+
70
+ # Add a custom page method (like a tag, but this is for your ERB pages)
71
+ addPageMethod(:m_my_method, 'Mentawai::Page::Method::Out', 'print')
72
+ end
73
+
74
+ end
75
+ EOF
76
+
77
+ APP_MANAGER_FILE_2 = <<EOF
78
+ include Mentawai::Core
79
+
80
+ class AppManager < ApplicationManager
81
+
82
+ def init(appContext)
83
+
84
+ # Define an action...
85
+ action(:action_name => "/Hello", :class_name => "MyApp2::Hello").on(:success => fwd("hello.erb"))
86
+
87
+ end
88
+
89
+ end
90
+ EOF
91
+
92
+
93
+ ACTION_FILE_1 = <<EOF
94
+
95
+ module MyApp1
96
+
97
+ class Hello < Mentawai::Core::Action
98
+
99
+ def execute
100
+
101
+ username = input['username']
102
+
103
+ username = "NO USER" if username.nil?
104
+
105
+ output['username'] = username.upcase
106
+
107
+ :success
108
+
109
+ end
110
+
111
+ def sayHi
112
+
113
+ output['username'] = "Roger"
114
+
115
+ :success
116
+
117
+ end
118
+
119
+ def sayHello
120
+
121
+ output['username'] = "Rick"
122
+
123
+ :success
124
+
125
+ end
126
+ end
127
+
128
+ end
129
+ EOF
130
+
131
+ ACTION_FILE_2 = <<EOF
132
+
133
+ module MyApp2
134
+
135
+ class Hello < Mentawai::Core::Action
136
+
137
+ def sayHi
138
+
139
+ output['username'] = "Sergio"
140
+
141
+ :success
142
+
143
+ end
144
+
145
+ def sayHello
146
+
147
+ output['username'] = "Rubem"
148
+
149
+ :success
150
+
151
+ end
152
+
153
+ end
154
+ end
155
+ EOF
156
+
157
+ VIEW_FILE_1 = <<EOF
158
+ <html>
159
+ <body>
160
+ <title>ROOT ('/') Mentawai Application</title>
161
+ <!-- using menta method m_out -->
162
+ <h3>Hello1: <%= m_out('username') %></h3>
163
+ <!-- using custom page method -->
164
+ <h3>Hello2: <%= m_my_method('username') %></h3>
165
+ </body>
166
+ </html>
167
+ EOF
168
+
169
+ VIEW_FILE_2 = <<EOF
170
+ <html>
171
+ <body>
172
+ <title>myapp ('/myapp') Mentawai Application</title>
173
+ <!-- using menta method m_out -->
174
+ <h3>Hi1: <%= m_out('username') %></h3>
175
+ </body>
176
+ </html>
177
+ EOF
178
+
179
+
180
+ def create_app(app)
181
+ Dir.mkdir(app)
182
+
183
+ Dir.mkdir(app + '/ROOT')
184
+ Dir.mkdir(app + '/ROOT/WEB-INF')
185
+ Dir.mkdir(app + '/ROOT/WEB-INF/src')
186
+ Dir.mkdir(app + '/ROOT/WEB-INF/lib')
187
+
188
+ Dir.mkdir(app + '/myapp')
189
+ Dir.mkdir(app + '/myapp/WEB-INF')
190
+ Dir.mkdir(app + '/myapp/WEB-INF/src')
191
+ Dir.mkdir(app + '/myapp/WEB-INF/lib')
192
+
193
+ f = File.open(app + '/start.rb', 'w')
194
+ f.print START_FILE
195
+ f.close
196
+
197
+ f = File.open(app + '/ROOT/WEB-INF/app_manager.rb', 'w')
198
+ f.print APP_MANAGER_FILE_1
199
+ f.close
200
+
201
+ f = File.open(app + '/ROOT/WEB-INF/src/hello.rb', 'w')
202
+ f.print ACTION_FILE_1
203
+ f.close
204
+
205
+ f = File.open(app + '/ROOT/hello.erb', 'w')
206
+ f.print VIEW_FILE_1
207
+ f.close
208
+
209
+ f = File.open(app + '/myapp/WEB-INF/app_manager.rb', 'w')
210
+ f.print APP_MANAGER_FILE_2
211
+ f.close
212
+
213
+ f = File.open(app + '/myapp/WEB-INF/src/hello.rb', 'w')
214
+ f.print ACTION_FILE_2
215
+ f.close
216
+
217
+ f = File.open(app + '/myapp/hello.erb', 'w')
218
+ f.print VIEW_FILE_2
219
+ f.close
220
+
221
+ puts "Mentawai web container created: #{app}"
222
+ puts "To run: ruby start.rb inside \"#{app}\""
223
+ puts
224
+ puts "Successfuly created a mentawai server!"
225
+ end
226
+
227
+ if %w(-v --version).include? ARGV.first
228
+ version
229
+ exit(0)
230
+ end
231
+
232
+ if %w(-h --help).include?(ARGV.first) || ARGV.length == 0 then
233
+ help
234
+ exit(0)
235
+ end
236
+
237
+ if %w(-c --create).include?(ARGV.first)
238
+ arg = ARGV[1] || 'mentawai'
239
+ create_app(arg)
240
+ exit(0)
241
+ end
242
+
243
+ puts "Invalid argument!"
244
+
data/config/hoe.rb CHANGED
@@ -2,11 +2,14 @@ require 'mentawai/version'
2
2
 
3
3
  AUTHOR = 'Sergio Oliveira Jr.' # can also be an array of Authors
4
4
  EMAIL = "sergio.oliveira.jr@gmail.com"
5
- DESCRIPTION = "A port of the Mentawai framework to Ruby + Mongrel + Rack"
5
+ DESCRIPTION = "Mentawai Web Container, Server and Framework in Ruby"
6
6
  GEM_NAME = 'mentawai' # what ppl will type to install your gem
7
7
  RUBYFORGE_PROJECT = 'mentawai' # The unix name for your project
8
8
  HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
9
9
  DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
10
+ EXTRA_DEPENDENCIES = [
11
+ # ['activesupport', '>= 1.3.1']
12
+ ] # An array of rubygem dependencies [name, version]
10
13
 
11
14
  @config_file = "~/.rubyforge/user-config.yml"
12
15
  @config = nil
@@ -28,26 +31,26 @@ Run 'rubyforge setup' to prepare your env for access to Rubyforge
28
31
  end
29
32
 
30
33
 
31
- REV = nil
32
- # UNCOMMENT IF REQUIRED:
33
- # REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
34
+ REV = nil
35
+ # UNCOMMENT IF REQUIRED:
36
+ # REV = YAML.load(`svn info`)['Revision']
34
37
  VERS = Mentawai::VERSION::STRING + (REV ? ".#{REV}" : "")
35
38
  RDOC_OPTS = ['--quiet', '--title', 'mentawai documentation',
36
39
  "--opname", "index.html",
37
- "--line-numbers",
40
+ "--line-numbers",
38
41
  "--main", "README",
39
42
  "--inline-source"]
40
43
 
41
44
  class Hoe
42
- def extra_deps
43
- @extra_deps.reject! { |x| Array(x).first == 'hoe' }
45
+ def extra_deps
46
+ @extra_deps.reject! { |x| Array(x).first == 'hoe' }
44
47
  @extra_deps
45
- end
48
+ end
46
49
  end
47
50
 
48
51
  # Generate all the Rake tasks
49
52
  # Run 'rake -T' to see list of generated tasks (from gem root directory)
50
- hoe = Hoe.new(GEM_NAME, VERS) do |p|
53
+ $hoe = Hoe.new(GEM_NAME, VERS) do |p|
51
54
  p.developer(AUTHOR, EMAIL)
52
55
  p.description = DESCRIPTION
53
56
  p.summary = DESCRIPTION
@@ -55,16 +58,16 @@ hoe = Hoe.new(GEM_NAME, VERS) do |p|
55
58
  p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
56
59
  p.test_globs = ["test/**/test_*.rb"]
57
60
  p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
58
-
61
+
59
62
  # == Optional
60
63
  p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
61
- #p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
62
-
63
- #p.spec_extras = {} # A hash of extra values to set in the gemspec.
64
-
65
- end
64
+ #p.extra_deps = EXTRA_DEPENDENCIES
65
+
66
+ #p.spec_extras = {} # A hash of extra values to set in the gemspec.
67
+ end
66
68
 
67
- CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
69
+ CHANGES = $hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
68
70
  PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
69
- hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
70
- hoe.rsync_args = '-av --delete --ignore-errors'
71
+ $hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
72
+ $hoe.rsync_args = '-av --delete --ignore-errors'
73
+ $hoe.spec.post_install_message = File.open(File.dirname(__FILE__) + "/../PostInstall.txt").read rescue ""
@@ -13,5 +13,3 @@ require 'rubygems'
13
13
  end
14
14
 
15
15
  $:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
16
-
17
- require 'mentawai'
@@ -0,0 +1,64 @@
1
+
2
+ module Mentawai
3
+
4
+ class Application
5
+
6
+ attr_reader :appContext, :contextPath, :appManagerFilename, :appManagerClass, :appManagerFile, :appManager, :extension, :default_page, :listing_allowed, :dirs_allowed_for_listing
7
+
8
+ def initialize(params)
9
+
10
+ @appContext = Hash.new
11
+
12
+ @contextPath = params[:app_context] || '/'
13
+
14
+ @appManagerFilename = params[:app_manager_file] || 'app_manager.rb'
15
+ @appManagerFilename = ".#{contextPathDir}/WEB-INF/#{@appManagerFilename.sub(/^\//, "")}"
16
+ raise "Application manager does not exist: " + @appManagerFilename if not File.exists?(@appManagerFilename)
17
+
18
+ @appManagerClass = params[:app_manager_class] || 'AppManager'
19
+
20
+ @appManagerFile = File.new(@appManagerFilename)
21
+
22
+ @appManager = nil
23
+
24
+ @extension = params[:action_extension] || 'mtw'
25
+
26
+ @default_page = params[:default_page] || 'index.erb'
27
+
28
+ @listing_allowed = params[:listing_allowed] || false
29
+
30
+ @dirs_allowed_for_listing = params[:dirs_allowed_for_listing] || []
31
+
32
+ @appManagerFileLastModified = 0
33
+
34
+ end
35
+
36
+ def contextPathDir
37
+ if contextPath == '/'
38
+ "/ROOT"
39
+ else
40
+ contextPath
41
+ end
42
+ end
43
+
44
+ def to_s
45
+ "#{contextPath} (#{appManagerFilename}/#{appManagerClass})"
46
+ end
47
+
48
+ def reloadAppManager(force = false)
49
+ if force || @appManagerFile.mtime != @appManagerFileLastModified then
50
+ if @appManagerFileLastModified == 0 then
51
+ puts "Loading app manager: " + @appManagerFilename
52
+ else
53
+ puts "Reloading app manager: " + @appManagerFilename
54
+ end
55
+ load @appManagerFilename
56
+ @appManager = eval(appManagerClass + ".new(self)")
57
+ @appManager.init(@appContext)
58
+ @appManagerFileLastModified = @appManagerFile.mtime
59
+ end
60
+ end
61
+
62
+ end
63
+
64
+ end
@@ -5,6 +5,33 @@ module Mentawai
5
5
 
6
6
  attr_accessor :input, :output, :session, :application, :locale, :cookies, :page
7
7
 
8
+ def messages
9
+ return nil if output.nil?
10
+ msgs = output['messages']
11
+ if not msgs
12
+ output['messages'] = msgs = Array.new
13
+ end
14
+ msgs
15
+ end
16
+
17
+ def errors
18
+ return nil if output.nil?
19
+ errs = output['errors']
20
+ if not errs
21
+ output['errors'] = errs = Array.new
22
+ end
23
+ errs
24
+ end
25
+
26
+ def fieldErrors
27
+ return nil if output.nil?
28
+ fieldErrs = output['fieldErrors']
29
+ if not fieldErrs
30
+ output['fieldErrors'] = fieldErrs = Hash.new
31
+ end
32
+ fieldErrs
33
+ end
34
+
8
35
  end
9
36
 
10
37
  end
@@ -40,6 +40,7 @@ module Mentawai
40
40
 
41
41
  alias [] get
42
42
  alias []= put
43
+ alias each values
43
44
 
44
45
  end
45
46