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.
@@ -0,0 +1,78 @@
1
+ require 'mentawai/page/page_method'
2
+
3
+ module Mentawai
4
+ module Page
5
+ module Method
6
+
7
+ class Message < Mentawai::Page::PageMethod
8
+
9
+ def initialize(action, parameters)
10
+ super
11
+ @errors = output['errors']
12
+ @messages = output['messages']
13
+ @fieldErrors = output['fieldErrors']
14
+ @fieldName = params[:field]
15
+ end
16
+
17
+ attr_reader :errors, :messages, :fieldErrors
18
+
19
+ def get_default_key
20
+ :field
21
+ end
22
+
23
+ def hasErrors
24
+ return false if @errors.nil? || !@errors.is_a?(Array)
25
+ !@errors.empty?
26
+ end
27
+
28
+ def hasError
29
+ if @fieldName
30
+ hasFieldError
31
+ else
32
+ hasErrors
33
+ end
34
+ end
35
+
36
+ def hasMessages
37
+ return false if @messages.nil? || !@messages.is_a?(Array)
38
+ !@messages.empty?
39
+ end
40
+
41
+ alias hasMessage hasMessages
42
+
43
+ def hasFieldError
44
+ raise "Missing field for field error!" if @fieldName.nil?
45
+ return false if @fieldErrors.nil? || !@fieldErrors.is_a?(Hash)
46
+ @fieldErrors.key?(@fieldName)
47
+ end
48
+
49
+ def hasFieldErrors
50
+ return false if @fieldErrors.nil? || !@fieldErrors.is_a?(Hash) || @fieldErrors.empty?
51
+ true
52
+ end
53
+
54
+ def fieldError
55
+ raise "Missing field for field error!" if @fieldName.nil?
56
+ return nil if @fieldErrors.nil? || !@fieldErrors.is_a?(Hash)
57
+ @fieldErrors[@fieldName]
58
+ end
59
+
60
+ def error
61
+ if @fieldName
62
+ fieldError
63
+ else
64
+ return nil if @errors.nil? || !@errors.is_a?(Array) || @errors.empty?
65
+ @errors[0]
66
+ end
67
+ end
68
+
69
+ def message
70
+ return nil if @messages.nil? || !@messages.is_a?(Array) || @messages.empty?
71
+ @messages[0]
72
+ end
73
+
74
+ end
75
+
76
+ end
77
+ end
78
+ end
@@ -3,8 +3,9 @@ module Mentawai
3
3
 
4
4
  class PageMethod
5
5
 
6
- def initialize(action, parameters)
7
- @action = action
6
+ def initialize(controller, parameters)
7
+ @controller = controller
8
+ @action = controller.action
8
9
  @params = turn_to_hash(parameters)
9
10
  end
10
11
 
@@ -58,8 +59,20 @@ module Mentawai
58
59
  @action.page
59
60
  end
60
61
 
62
+ def controller
63
+ @controller
64
+ end
65
+
66
+ def consequence
67
+ @controller.consequence
68
+ end
69
+
61
70
  protected
62
71
 
72
+ def get_default_key
73
+ :value
74
+ end
75
+
63
76
  def find_value(name)
64
77
  return nil if @action.nil?
65
78
 
@@ -126,7 +139,7 @@ module Mentawai
126
139
  elsif parameters.is_a?(Hash) then
127
140
  parameters
128
141
  else
129
- { :value => parameters.to_s }
142
+ { get_default_key => parameters.to_s }
130
143
  end
131
144
  end
132
145
 
@@ -1,6 +1,7 @@
1
1
  require 'rack'
2
2
  require 'mentawai/loader'
3
3
  require 'mentawai/session/menta_session'
4
+ require 'mentawai/handler/menta_handler'
4
5
 
5
6
  module Mentawai
6
7
 
@@ -11,7 +12,7 @@ module Mentawai
11
12
  def initialize(path = nil)
12
13
 
13
14
  @host = "127.0.0.1"
14
- @port = 8080
15
+ @port = 8081
15
16
 
16
17
  @apps = Hash.new
17
18
 
@@ -21,12 +22,30 @@ module Mentawai
21
22
  @loader = Mentawai::Loader.new(path + '/Mentawai')
22
23
  @loader.reloadFiles
23
24
  end
25
+ end
24
26
 
27
+ attr_reader :apps
28
+
29
+ def add_application(app_options)
30
+
31
+ app = Application.new(app_options)
32
+
33
+ raise "Context already exists: " + app.contextPath if @apps.has_key?(app.contextPath)
34
+
35
+ # add /WEB-INF/src and lib directory to the load path...
36
+ $:.unshift(".#{app.contextPathDir}/WEB-INF/lib")
37
+ $:.unshift(".#{app.contextPathDir}/WEB-INF/src")
38
+
39
+ @apps[app.contextPath] = app
40
+
41
+ app.reloadAppManager
42
+
25
43
  end
26
44
 
27
- def application(contextPath, appManagerFilename, appManagerClass)
28
- raise "Context already exists: " + contextPath if @apps.has_key?(contextPath)
29
- @apps[contextPath] = Application.new(contextPath, appManagerFilename, appManagerClass)
45
+ alias add add_application
46
+
47
+ def contexts
48
+ @apps.keys
30
49
  end
31
50
 
32
51
  def call(env)
@@ -37,8 +56,20 @@ module Mentawai
37
56
  req = Rack::Request.new(env)
38
57
  res = Rack::Response.new(env)
39
58
 
59
+ contextPath = find_context_path(req.fullpath)
60
+
61
+ env['menta.contextPath'] = contextPath
62
+
63
+ app = @apps[contextPath]
64
+ app.reloadAppManager(filesLoaded > 0)
65
+
66
+ controller = Mentawai::Core::Controller.new(app)
67
+ controller.service(env, req, res)
68
+ end
69
+
70
+ def find_context_path(fullpath)
40
71
  # Extract context path from URL...
41
- if req.fullpath =~ /(\/[^\/]*)/ then
72
+ if fullpath =~ /(\/[^\/]*)/ then
42
73
  contextPath = $1
43
74
  else
44
75
  raise "Cannot get context path: " + env.fullpath
@@ -46,61 +77,22 @@ module Mentawai
46
77
 
47
78
  # Decide about context path...
48
79
  if @apps.has_key?(contextPath) then
49
- # context path was found! (NOOP)
80
+ contextPath
50
81
  elsif @apps.has_key?('/') then
51
- contextPath = '/'
82
+ '/'
52
83
  else
53
84
  raise "Cannot find context: " + contextPath
54
85
  end
55
-
56
- env['menta.contextPath'] = contextPath
57
-
58
- app = @apps[contextPath]
59
- app.reloadAppManager(filesLoaded > 0)
60
-
61
- controller = Mentawai::Core::Controller.new(app.contextPath, app.appContext, app.appManager)
62
- controller.service(env, req, res)
63
86
  end
64
87
 
65
88
  def start
66
89
 
67
90
  session_config = { :cookie_expire_after => 0, :session_expire_after => 10 }
68
91
  session_server = Mentawai::Session::MentaSession.new(self, session_config)
69
- config = {:Host => @host, :Port => @port}
70
- Rack::Handler::Mongrel.run(session_server, config)
71
- end
72
-
73
- class Application
74
-
75
- attr_reader :contextPath, :appContext, :appManagerFilename, :appManagerClass, :appManagerFile, :appManager
76
-
77
- def initialize(contextPath, appManagerFilename, appManagerClass)
78
- raise "Application manager does not exist: " + appManagerFilename if not File.exists?(appManagerFilename)
79
- @appContext = Hash.new
80
- @contextPath = contextPath
81
- @appManagerFilename = appManagerFilename
82
- @appManagerClass = appManagerClass
83
- @appManagerFile = File.new(appManagerFilename)
84
- @appManagerFileLastModified = 0
85
- reloadAppManager
86
- end
87
-
88
- def reloadAppManager(force = false)
89
- if force || @appManagerFile.mtime != @appManagerFileLastModified then
90
- if @appManagerFileLastModified == 0 then
91
- puts "Loading app manager: " + @appManagerFilename
92
- else
93
- puts "Reloading app manager: " + @appManagerFilename
94
- end
95
- load @appManagerFilename
96
- @appManager = eval(appManagerClass + ".new")
97
- @appManager.init(@appContext)
98
- @appManagerFileLastModified = @appManagerFile.mtime
99
- end
100
- end
101
-
92
+ config = {:Host => @host, :Port => @port }
93
+ Mentawai::Handler::MentaHandler.run(self, session_server, config)
102
94
  end
103
95
 
104
96
  end
105
97
 
106
- end
98
+ end
@@ -0,0 +1,12 @@
1
+
2
+ class Array
3
+
4
+ alias add push
5
+ alias remove pop
6
+ alias del pop
7
+
8
+ alias add_first unshift
9
+ alias remove_first shift
10
+ alias del_first shift
11
+
12
+ end
@@ -0,0 +1,51 @@
1
+
2
+ module Mentawai
3
+ module Util
4
+
5
+ class Properties
6
+
7
+ def self.load(filename)
8
+ return nil if not File.exists?(filename)
9
+ properties = {}
10
+
11
+ value = key = ''
12
+ multiline = false
13
+
14
+ File.open(filename, 'r') do |file|
15
+ file.each do |line|
16
+ extra_space = line =~ /\\ +\n?$/
17
+ line.strip!
18
+ line.chop! if extra_space
19
+ if multiline then
20
+ value += "\n" + line
21
+ value += " " if extra_space
22
+ if value =~ /\\$/ then
23
+ value.chop!
24
+ next
25
+ else
26
+ multiline = false
27
+ end
28
+ else
29
+ next if line =~ /^\#/ || line == ''
30
+ index = line.index('=')
31
+ next if not index
32
+ key = line[0..index - 1].strip
33
+ value = line[index + 1..-1].strip
34
+ value += " " if extra_space
35
+ end
36
+
37
+ if value =~ /\\$/ then
38
+ multiline = true
39
+ value.chop!
40
+ next
41
+ end
42
+ properties[key] = value
43
+ end
44
+ end
45
+ properties
46
+ end
47
+
48
+ end
49
+
50
+ end
51
+ end
@@ -1,9 +1,9 @@
1
1
  module Mentawai #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
- MINOR = 5
4
+ MINOR = 6
5
5
  TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
9
- end
9
+ end
data/lib/mentawai.rb CHANGED
@@ -6,6 +6,7 @@ root = File.expand_path(File.dirname(__FILE__))
6
6
 
7
7
  require root + '/mentawai/loader'
8
8
  require root + '/mentawai/server'
9
+ require root + '/mentawai/application'
9
10
 
10
11
  # Now loop and load everything inside '/mentawai/**'
11
12
 
data/script/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/mentawai.rb'}"
9
+ puts "Loading mentawai gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
@@ -0,0 +1 @@
1
+ @ruby script/console %*
@@ -0,0 +1 @@
1
+ @ruby script/destroy %*
@@ -0,0 +1 @@
1
+ @ruby script/generate %*
data/script/txt2html CHANGED
@@ -1,8 +1,12 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ GEM_NAME = 'mentawai' # what ppl will type to install your gem
4
+ RUBYFORGE_PROJECT = 'mentawai'
5
+
3
6
  require 'rubygems'
4
7
  begin
5
8
  require 'newgem'
9
+ require 'rubyforge'
6
10
  rescue LoadError
7
11
  puts "\n\nGenerating the website requires the newgem RubyGem"
8
12
  puts "Install: gem install newgem\n\n"
@@ -11,10 +15,14 @@ end
11
15
  require 'redcloth'
12
16
  require 'syntax/convertors/html'
13
17
  require 'erb'
14
- require File.dirname(__FILE__) + '/../lib/mentawai/version.rb'
18
+ require File.dirname(__FILE__) + "/../lib/#{GEM_NAME}/version.rb"
15
19
 
16
20
  version = Mentawai::VERSION::STRING
17
- download = 'http://rubyforge.org/projects/mentawai'
21
+ download = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
22
+
23
+ def rubyforge_project_id
24
+ RubyForge.new.autoconfig["group_ids"][RUBYFORGE_PROJECT]
25
+ end
18
26
 
19
27
  class Fixnum
20
28
  def ordinal
@@ -42,10 +50,9 @@ end
42
50
 
43
51
  if ARGV.length >= 1
44
52
  src, template = ARGV
45
- template ||= File.join(File.dirname(__FILE__), '/../website/template.rhtml')
46
-
53
+ template ||= File.join(File.dirname(__FILE__), '/../website/template.html.erb')
47
54
  else
48
- puts("Usage: #{File.split($0).last} source.txt [template.rhtml] > output.html")
55
+ puts("Usage: #{File.split($0).last} source.txt [template.html.erb] > output.html")
49
56
  exit!
50
57
  end
51
58
 
@@ -55,7 +62,8 @@ title = nil
55
62
  body = nil
56
63
  File.open(src) do |fsrc|
57
64
  title_text = fsrc.readline
58
- body_text = fsrc.read
65
+ body_text_template = fsrc.read
66
+ body_text = ERB.new(body_text_template).result(binding)
59
67
  syntax_items = []
60
68
  body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</\1>!m){
61
69
  ident = syntax_items.length
@@ -0,0 +1 @@
1
+ @ruby script/txt2html %*
@@ -1,5 +1,6 @@
1
1
  desc 'Release the website and new gem version'
2
- task :deploy => [:check_version, :website, :release] do
2
+ #task :deploy => [:check_version, :website, :release] do
3
+ task :deploy => [:check_version, :release] do
3
4
  puts "Remember to create SVN tag:"
4
5
  puts "svn copy svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/trunk " +
5
6
  "svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
@@ -23,12 +24,18 @@ end
23
24
 
24
25
  desc 'Install the package as a gem, without generating documentation(ri/rdoc)'
25
26
  task :install_gem_no_doc => [:clean, :package] do
26
- sh "#{'sudo ' unless Hoe::WINDOZE }gem install pkg/*.gem --no-rdoc --no-ri"
27
+ if Hoe::WINDOZE
28
+ suf = 'cmd.exe /c'
29
+ else
30
+ suf = 'sudo'
31
+ end
32
+
33
+ sh "#{suf} gem install pkg/*.gem --no-rdoc --no-ri"
27
34
  end
28
35
 
29
36
  namespace :manifest do
30
37
  desc 'Recreate Manifest.txt to include ALL files'
31
38
  task :refresh do
32
- `rake check_manifest | patch -p0 > Manifest.txt`
39
+ `rake check_manifest | patch -p0`
33
40
  end
34
41
  end
data/tasks/website.rake CHANGED
@@ -10,8 +10,8 @@ task :website_upload do
10
10
  host = "#{rubyforge_username}@rubyforge.org"
11
11
  remote_dir = "/var/www/gforge-projects/#{PATH}/"
12
12
  local_dir = 'website'
13
- sh %{rsync -aCv #{local_dir}/ #{host}:#{remote_dir}}
13
+ sh %{cmd.exe /c rsync.exe -aCv #{local_dir}/ #{host}:#{remote_dir}}
14
14
  end
15
15
 
16
16
  desc 'Generate and upload website files'
17
- task :website => [:website_generate, :website_upload, :publish_docs]
17
+ task :website => [:website_generate, :website_upload, :publish_docs]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mentawai
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergio Oliveira Jr.
@@ -9,11 +9,11 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-03-17 00:00:00 -08:00
12
+ date: 2008-04-30 00:00:00 -03:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
16
- description: A port of the Mentawai framework to Ruby + Mongrel + Rack
16
+ description: Mentawai Web Container, Server and Framework in Ruby
17
17
  email:
18
18
  - sergio.oliveira.jr@gmail.com
19
19
  executables:
@@ -24,18 +24,20 @@ extra_rdoc_files:
24
24
  - History.txt
25
25
  - License.txt
26
26
  - Manifest.txt
27
+ - PostInstall.txt
27
28
  - README.txt
28
- - website/index.txt
29
29
  files:
30
30
  - History.txt
31
31
  - License.txt
32
32
  - Manifest.txt
33
+ - PostInstall.txt
33
34
  - README.txt
34
35
  - Rakefile
35
36
  - bin/menta
36
37
  - config/hoe.rb
37
38
  - config/requirements.rb
38
39
  - lib/mentawai.rb
40
+ - lib/mentawai/application.rb
39
41
  - lib/mentawai/core/action.rb
40
42
  - lib/mentawai/core/action_config.rb
41
43
  - lib/mentawai/core/app_context.rb
@@ -47,32 +49,37 @@ files:
47
49
  - lib/mentawai/core/invocation_chain.rb
48
50
  - lib/mentawai/core/output.rb
49
51
  - lib/mentawai/core/session.rb
52
+ - lib/mentawai/handler/menta_handler.rb
53
+ - lib/mentawai/i18n/loc_manager.rb
50
54
  - lib/mentawai/loader.rb
55
+ - lib/mentawai/page/methods/content_type.rb
56
+ - lib/mentawai/page/methods/messages.rb
51
57
  - lib/mentawai/page/methods/out.rb
52
58
  - lib/mentawai/page/page_method.rb
53
59
  - lib/mentawai/server.rb
54
60
  - lib/mentawai/session/menta_session.rb
55
61
  - lib/mentawai/session/rack_session.rb
62
+ - lib/mentawai/util/array.rb
63
+ - lib/mentawai/util/properties.rb
56
64
  - lib/mentawai/util/string.rb
57
65
  - lib/mentawai/version.rb
58
- - log/debug.log
66
+ - script/console
67
+ - script/console.cmd
59
68
  - script/destroy
69
+ - script/destroy.cmd
60
70
  - script/generate
71
+ - script/generate.cmd
61
72
  - script/txt2html
73
+ - script/txt2html.cmd
62
74
  - setup.rb
63
75
  - tasks/deployment.rake
64
76
  - tasks/environment.rake
65
77
  - tasks/website.rake
66
78
  - test/test_helper.rb
67
79
  - test/test_mentawai.rb
68
- - website/index.html
69
- - website/index.txt
70
- - website/javascripts/rounded_corners_lite.inc.js
71
- - website/stylesheets/screen.css
72
- - website/template.rhtml
73
80
  has_rdoc: true
74
81
  homepage: http://mentawai.rubyforge.org
75
- post_install_message:
82
+ post_install_message: ""
76
83
  rdoc_options:
77
84
  - --main
78
85
  - README.txt
@@ -93,10 +100,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
100
  requirements: []
94
101
 
95
102
  rubyforge_project: mentawai
96
- rubygems_version: 1.0.1
103
+ rubygems_version: 1.1.1
97
104
  signing_key:
98
105
  specification_version: 2
99
- summary: A port of the Mentawai framework to Ruby + Mongrel + Rack
106
+ summary: Mentawai Web Container, Server and Framework in Ruby
100
107
  test_files:
101
- - test/test_mentawai.rb
102
108
  - test/test_helper.rb
109
+ - test/test_mentawai.rb
data/website/index.html DELETED
@@ -1,93 +0,0 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
- <head>
5
- <link rel="stylesheet" href="stylesheets/screen.css" type="text/css" media="screen" />
6
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
7
- <title>
8
- mentawai
9
- </title>
10
- <script src="javascripts/rounded_corners_lite.inc.js" type="text/javascript"></script>
11
- <style>
12
-
13
- </style>
14
- <script type="text/javascript">
15
- window.onload = function() {
16
- settings = {
17
- tl: { radius: 10 },
18
- tr: { radius: 10 },
19
- bl: { radius: 10 },
20
- br: { radius: 10 },
21
- antiAlias: true,
22
- autoPad: true,
23
- validTags: ["div"]
24
- }
25
- var versionBox = new curvyCorners(settings, document.getElementById("version"));
26
- versionBox.applyCornersToAll();
27
- }
28
- </script>
29
- </head>
30
- <body>
31
- <div id="main">
32
-
33
- <h1>mentawai</h1>
34
- <div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/mentawai"; return false'>
35
- <p>Get Version</p>
36
- <a href="http://rubyforge.org/projects/mentawai" class="numbers">0.5.0</a>
37
- </div>
38
- <h1>&#x2192; &#8216;mentawai&#8217;</h1>
39
-
40
-
41
- <h2>What</h2>
42
-
43
-
44
- <h2>Installing</h2>
45
-
46
-
47
- <p><pre class='syntax'><span class="ident">sudo</span> <span class="ident">gem</span> <span class="ident">install</span> <span class="ident">mentawai</span></pre></p>
48
-
49
-
50
- <h2>The basics</h2>
51
-
52
-
53
- <h2>Demonstration of usage</h2>
54
-
55
-
56
- <h2>Forum</h2>
57
-
58
-
59
- <p><a href="http://groups.google.com/group/mentawai">http://groups.google.com/group/mentawai</a></p>
60
-
61
-
62
- <p><span class="caps">TODO</span> &#8211; create Google Group &#8211; mentawai</p>
63
-
64
-
65
- <h2>How to submit patches</h2>
66
-
67
-
68
- <p>Read the <a href="http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/">8 steps for fixing other people&#8217;s code</a> and for section <a href="http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/#8b-google-groups">8b: Submit patch to Google Groups</a>, use the Google Group above.</p>
69
-
70
-
71
- <p>The trunk repository is <code>svn://rubyforge.org/var/svn/mentawai/trunk</code> for anonymous access.</p>
72
-
73
-
74
- <h2>License</h2>
75
-
76
-
77
- <p><span class="caps">LGPL</span></p>
78
-
79
-
80
- <h2>Contact</h2>
81
-
82
-
83
- <p>Comments are welcome. Send an email to &#8220;Sergio Oliveira Jr.&#8221; (sergio.oliveira.jr at gmail.com)</p>
84
- <p class="coda">
85
- <a href="FIXME email">FIXME full name</a>, 17th March 2008<br>
86
- Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
87
- </p>
88
- </div>
89
-
90
- <!-- insert site tracking codes here, like Google Urchin -->
91
-
92
- </body>
93
- </html>