bivouac 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. data/README +15 -0
  2. data/bin/bivouac +5 -10
  3. data/doc/rdoc/classes/BivouacHelpers/HtmlView.html +46 -37
  4. data/doc/rdoc/classes/BivouacHelpers/ScriptAculoUsView.html +27 -20
  5. data/doc/rdoc/created.rid +1 -1
  6. data/doc/rdoc/files/README.html +45 -1
  7. data/doc/rdoc/files/lib/bivouac/helpers/view/goh/html_rb.html +1 -1
  8. data/doc/rdoc/files/lib/bivouac/helpers/view/goh/javascript_rb.html +1 -1
  9. data/doc/rdoc/files/lib/bivouac/helpers/view/goh/scriptaculous_rb.html +1 -1
  10. data/examples/bivouac_sample/Rakefile +0 -0
  11. data/examples/bivouac_sample/app/controllers/toggle_sortable.rb +2 -1
  12. data/examples/bivouac_sample/app/views/_sortable_result.rb +1 -1
  13. data/examples/bivouac_sample/script/console +0 -0
  14. data/examples/bivouac_sample/script/generate +0 -0
  15. data/examples/bivouac_sample/script/plugin +0 -0
  16. data/examples/bivouac_sample/script/server +0 -0
  17. data/examples/blog/Rakefile +56 -0
  18. data/examples/blog/app/blog.rb +107 -0
  19. data/examples/blog/app/controllers/comment.rb +17 -0
  20. data/examples/blog/app/controllers/index.rb +15 -0
  21. data/examples/blog/app/controllers/login.rb +33 -0
  22. data/examples/blog/app/controllers/logout.rb +15 -0
  23. data/examples/blog/app/controllers/not_found.rb +14 -0
  24. data/examples/blog/app/controllers/post.rb +48 -0
  25. data/examples/blog/app/helpers/_helpers.rb +30 -0
  26. data/examples/blog/app/helpers/blog.rb +14 -0
  27. data/examples/blog/app/models/comment.rb +18 -0
  28. data/examples/blog/app/models/post.rb +19 -0
  29. data/examples/blog/app/models/user.rb +12 -0
  30. data/examples/blog/app/views/_partials.rb +81 -0
  31. data/examples/blog/app/views/index/index.rb +23 -0
  32. data/examples/blog/app/views/layouts/default_layout.rb +40 -0
  33. data/examples/blog/app/views/login/login.rb +27 -0
  34. data/examples/blog/app/views/not_found.rb +13 -0
  35. data/examples/blog/app/views/post/add.rb +12 -0
  36. data/examples/blog/app/views/post/edit.rb +12 -0
  37. data/examples/blog/app/views/post/view.rb +14 -0
  38. data/examples/blog/config/console.rc +12 -0
  39. data/examples/blog/config/database.yml +3 -0
  40. data/examples/blog/config/environment.rb +58 -0
  41. data/examples/blog/db/blog.db +0 -0
  42. data/examples/blog/db/create.rb +11 -0
  43. data/examples/blog/db/migrate/001_users.rb +22 -0
  44. data/examples/blog/db/migrate/002_posts.rb +24 -0
  45. data/examples/blog/db/migrate/003_comments.rb +24 -0
  46. data/examples/blog/log/Blog.log +382 -0
  47. data/examples/{blog_goh → blog}/public/images/camping.png +0 -0
  48. data/examples/{blog_goh → blog}/public/index.html +3 -2
  49. data/examples/blog/public/javascripts/builder.js +136 -0
  50. data/examples/blog/public/javascripts/controls.js +965 -0
  51. data/examples/blog/public/javascripts/dragdrop.js +974 -0
  52. data/examples/blog/public/javascripts/effects.js +1122 -0
  53. data/examples/blog/public/javascripts/prototype.js +4320 -0
  54. data/examples/blog/public/javascripts/scriptaculous.js +58 -0
  55. data/examples/blog/public/javascripts/slider.js +275 -0
  56. data/examples/blog/public/javascripts/sound.js +55 -0
  57. data/examples/blog/public/javascripts/unittest.js +568 -0
  58. data/examples/blog/public/stylesheets/autocomplete.css +22 -0
  59. data/examples/blog/public/stylesheets/blog.css +107 -0
  60. data/examples/blog/script/console +12 -0
  61. data/examples/blog/script/generate +17 -0
  62. data/examples/blog/script/plugin +16 -0
  63. data/examples/blog/script/server +135 -0
  64. data/examples/blog/test/test_comment.rb +22 -0
  65. data/examples/blog/test/test_index.rb +22 -0
  66. data/examples/blog/test/test_login.rb +22 -0
  67. data/examples/blog/test/test_logout.rb +18 -0
  68. data/examples/blog/test/test_post.rb +30 -0
  69. data/examples/blog/test/test_post_new.rb +22 -0
  70. data/lib/bivouac.rb +2 -2
  71. data/lib/bivouac/commands/generate.rb +48 -8
  72. data/lib/bivouac/commands/plugin.rb +30 -15
  73. data/lib/bivouac/ext/filtering_camping.rb +46 -0
  74. data/lib/bivouac/helpers/view/goh/html.rb +9 -0
  75. data/lib/bivouac/helpers/view/goh/scriptaculous.rb +12 -8
  76. data/lib/bivouac/tasks/bivouac.rb +1 -0
  77. data/lib/bivouac/tasks/framework.rake +8 -8
  78. data/lib/bivouac/tasks/plugins.rake +17 -1
  79. data/lib/bivouac/template.rb +0 -0
  80. data/lib/bivouac/template/{application_goh.rb → application.rb} +36 -12
  81. data/lib/bivouac/template/application/{helpers_goh.rb → helpers.rb} +1 -1
  82. data/lib/bivouac/template/console.rb +2 -4
  83. data/lib/bivouac/template/environment.rb +1 -1
  84. data/lib/bivouac/template/generate.rb +0 -0
  85. data/lib/bivouac/template/generate/create.rb +0 -0
  86. data/lib/bivouac/template/generate/helper.rb +12 -0
  87. data/lib/bivouac/template/generate/migrate.rb +0 -0
  88. data/lib/bivouac/template/generate/migrate_end.rb +1 -0
  89. data/lib/bivouac/template/plugin.rb +6 -1
  90. data/lib/bivouac/template/server.rb +124 -3
  91. data/lib/bivouac/template/static/builder.js +19 -19
  92. data/lib/bivouac/template/static/controls.js +74 -74
  93. data/lib/bivouac/template/static/dragdrop.js +167 -166
  94. data/lib/bivouac/template/static/effects.js +171 -163
  95. data/lib/bivouac/template/static/not_found_controller.rb +8 -4
  96. data/lib/bivouac/template/static/prototype.js +218 -119
  97. data/lib/bivouac/template/static/scriptaculous.js +22 -20
  98. data/lib/bivouac/template/static/slider.js +39 -39
  99. data/lib/bivouac/template/static/sound.js +11 -11
  100. data/lib/bivouac/template/static/unittest.js +16 -16
  101. metadata +96 -60
  102. data/examples/blog_goh/app/blog.rb +0 -72
  103. data/examples/blog_goh/app/controllers/add.rb +0 -19
  104. data/examples/blog_goh/app/controllers/comment.rb +0 -9
  105. data/examples/blog_goh/app/controllers/edit.rb +0 -18
  106. data/examples/blog_goh/app/controllers/index.rb +0 -8
  107. data/examples/blog_goh/app/controllers/info.rb +0 -11
  108. data/examples/blog_goh/app/controllers/login.rb +0 -15
  109. data/examples/blog_goh/app/controllers/logout.rb +0 -8
  110. data/examples/blog_goh/app/controllers/view.rb +0 -9
  111. data/examples/blog_goh/app/models/comment.rb +0 -5
  112. data/examples/blog_goh/app/models/post.rb +0 -5
  113. data/examples/blog_goh/app/models/user.rb +0 -4
  114. data/examples/blog_goh/app/views/_form.rb +0 -16
  115. data/examples/blog_goh/app/views/_login.rb +0 -13
  116. data/examples/blog_goh/app/views/_post.rb +0 -9
  117. data/examples/blog_goh/app/views/add.rb +0 -9
  118. data/examples/blog_goh/app/views/edit.rb +0 -9
  119. data/examples/blog_goh/app/views/index.rb +0 -12
  120. data/examples/blog_goh/app/views/layout.rb +0 -18
  121. data/examples/blog_goh/app/views/login.rb +0 -6
  122. data/examples/blog_goh/app/views/logout.rb +0 -6
  123. data/examples/blog_goh/app/views/view.rb +0 -20
  124. data/examples/blog_goh/config/environment.rb +0 -27
  125. data/examples/blog_goh/db/Blog.db +0 -0
  126. data/examples/blog_goh/db/create.rb +0 -8
  127. data/examples/blog_goh/db/migrate/comment.rb +0 -15
  128. data/examples/blog_goh/db/migrate/post.rb +0 -15
  129. data/examples/blog_goh/db/migrate/user.rb +0 -15
  130. data/examples/blog_goh/log/Blog.log +0 -75
  131. data/examples/blog_goh/public/stylesheets/style.css +0 -10
  132. data/examples/blog_goh/script/generate +0 -3
  133. data/examples/blog_goh/script/server +0 -5
  134. data/lib/bivouac/template/application/postamble.rb +0 -195
  135. data/lib/camping/cookies_sessions.rb +0 -39
@@ -8,7 +8,5 @@
8
8
  # DO NOT EDIT THIS FILE OR YOU REALLY KNOW WHAT YOU ARE DOING
9
9
  #
10
10
  require 'rubygems'
11
- app = File.dirname(__FILE__) + "/../app/<%= @conf.appfile %>.rb"
12
-
13
- ENV['BIVOUAC_ROOT'] = File.expand_path( File.dirname(__FILE__) + "/../" )
14
- system "ruby #{app} -c #{ARGV.join(' ')}"
11
+ server = File.dirname(__FILE__) + "/server"
12
+ system "ruby #{server} -C #{ARGV.join(' ')}"
@@ -16,7 +16,7 @@ module Bivouac
16
16
  def initialize
17
17
  @environment = OpenStruct.new(
18
18
  # Address to bind to
19
- :address => "<%= @conf.address %>",
19
+ :host => "<%= @conf.host %>",
20
20
 
21
21
  # Application port
22
22
  :port => <%= @conf.port %>,
File without changes
File without changes
@@ -0,0 +1,12 @@
1
+ #
2
+ # Project <%= @app.environment.appname %>
3
+ #
4
+ # Created using bivouac on <%= Time.now %>.
5
+ # Copyright (c) <%= Time.now.year %> __My__. All rights reserved.
6
+ #
7
+
8
+ module <%= @app.environment.appname %>::Helpers
9
+ def <%= @helper_name %>
10
+ # ...
11
+ end
12
+ end
File without changes
@@ -1,3 +1,4 @@
1
+ t.timestamps
1
2
  end
2
3
  end
3
4
 
@@ -8,4 +8,9 @@
8
8
  # DO NOT EDIT THIS FILE OR YOU REALLY KNOW WHAT YOU ARE DOING
9
9
  #
10
10
  require 'rubygems'
11
- require 'bivouac/commands/plugin'
11
+ DIRNAME = File.expand_path( File.dirname(__FILE__) )
12
+ ENV['BIVOUAC_ROOT'] = File.expand_path( DIRNAME + "/../" )
13
+ require ENV['BIVOUAC_ROOT'] + '/config/environment.rb'
14
+ require 'bivouac/commands/plugin'
15
+
16
+ Bivouac::Plugin.new( ARGV ).run( )
@@ -7,8 +7,129 @@
7
7
  #
8
8
  # DO NOT EDIT THIS FILE OR YOU REALLY KNOW WHAT YOU ARE DOING
9
9
  #
10
+ #!/usr/bin/env ruby
11
+
12
+ trap("INT") { exit }
10
13
  require 'rubygems'
11
- app = File.dirname(__FILE__) + "/../app/<%= @conf.appfile %>.rb"
14
+ require 'optparse'
15
+ require 'ostruct'
16
+ require 'stringio'
17
+ require 'camping'
18
+ require 'camping/server'
19
+
20
+ ## If the app run on Windows, check if win32/process is installed
21
+ windows_process = false
22
+ if /Windows/.match( ENV['OS'] )
23
+ begin
24
+ require 'win32/process'
25
+ windows_process = true
26
+ rescue LoadError => e
27
+ warn "`win32-process' is not installed!"
28
+ end
29
+ end
30
+ require 'simple-daemon'
31
+
32
+ # Set environment
33
+ DIRNAME = File.expand_path( File.dirname(__FILE__) )
34
+ ENV['BIVOUAC_ROOT'] = File.expand_path( DIRNAME + "/../" )
35
+ bivouac_app = File.expand_path( ENV['BIVOUAC_ROOT'] + "/app/<%= @conf.appfile %>.rb" )
36
+
37
+ # Daemonize ?
38
+ server_daemonize = nil
39
+
40
+ # Read configuration
41
+ require( ENV['BIVOUAC_ROOT'] + "/config/environment.rb" )
42
+ config = Bivouac::Environment.new( )
43
+
44
+ # Initialize database connection
45
+ database_connection = config.environment.db
46
+ if database_connection[:adapter] =~ /sqlite/
47
+ database_connection[:database] = ENV['BIVOUAC_ROOT'] + "/" + database_connection[:database]
48
+ end
49
+
50
+ # Create config structure for camping server
51
+ cs_conf = OpenStruct.new(
52
+ :host => config.environment.host,
53
+ :port => config.environment.port,
54
+ :database => database_connection,
55
+ :log => ENV['BIVOUAC_ROOT'] + "/log/<%= @conf.appname %>.log"
56
+ )
57
+
58
+ # Force server if specified
59
+ camping_server_configuration.server = config.environment.server_force if config.environment.server_force
60
+
61
+ # Parse options
62
+ opts = OptionParser.new do |opts|
63
+ opts.banner = "Usage: server [options]"
64
+ opts.separator ""
65
+ opts.separator "Specific options:"
66
+
67
+ opts.on("-h", "--host HOSTNAME", "Host for web server to bind to (#{cs_conf.host})") { |cs_conf.host| }
68
+ opts.on("-p", "--port NUM", "Port for web server (defaults to #{cs_conf.port})") { |cs_conf.port| }
69
+ opts.on("-C", "--console", "Run in console mode with IRB") {
70
+ cs_conf.server = "console";
71
+ ENV['IRBRC'] = ENV['BIVOUAC_ROOT'] + "/config/console.rc"
72
+ }
73
+ server_list = ["mongrel", "webrick", "console"]
74
+ opts.on("-s", "--server NAME", server_list, "Server to force (#{server_list.join(', ')})") { |cs_conf.server| }
75
+ opts.on("-d", "--daemon STATUS", ["start","stop","restart"], "Make server run as a Daemon.") { |server_daemonize| }
76
+
77
+ opts.separator ""
78
+ opts.separator "Common options:"
79
+
80
+ # No argument, shows at tail. This will print an options summary.
81
+ # Try it and see!
82
+ opts.on_tail("-?", "--help", "Show this message") do
83
+ puts opts
84
+ exit
85
+ end
86
+ end
87
+
88
+ begin
89
+ opts.parse! ARGV
90
+ rescue OptionParser::ParseError => ex
91
+ STDERR.puts "!! #{ex.message}"
92
+ puts "** use `server --help` for more details..."
93
+ exit 1
94
+ end
95
+
96
+ # Check that mongrel exists
97
+ if cs_conf.server.nil? || cs_conf.server == "mongrel"
98
+ begin
99
+ require 'mongrel'
100
+ cs_conf.server = "mongrel"
101
+ rescue LoadError
102
+ puts "!! could not load mongrel. Falling back to webrick."
103
+ cs_conf.server = "webrick"
104
+ end
105
+ end
106
+
107
+ # Create SimpleDaemon class
108
+ SimpleDaemon::WORKING_DIRECTORY = ENV['BIVOUAC_ROOT'] + "/log/"
109
+ class <%= @conf.appname %>Daemon < SimpleDaemon::Base
110
+ @@server = nil
111
+
112
+ def self.server=(s)
113
+ @@server = s
114
+ end
115
+
116
+ def self.start
117
+ @@server.start
118
+ end
119
+
120
+ def self.stop
121
+ @@server = nil
122
+ end
123
+ end
124
+
125
+ # Setup Camping Server
126
+ server = Camping::Server::Base.new(cs_conf, bivouac_app)
12
127
 
13
- ENV['BIVOUAC_ROOT'] = File.expand_path( File.dirname(__FILE__) + "/../" )
14
- system "ruby #{app} #{ARGV.join(' ')} --"
128
+ # Start or demonize
129
+ unless server_daemonize.nil?
130
+ silence_warnings { ARGV = [server_daemonize] }
131
+ <%= @conf.appname %>Daemon.server = server
132
+ <%= @conf.appname %>Daemon.daemonize
133
+ else
134
+ server.start
135
+ end
@@ -1,6 +1,6 @@
1
- // script.aculo.us builder.js v1.8.1, Thu Jan 03 22:07:12 -0500 2008
1
+ // script.aculo.us builder.js v1.8.2, Tue Nov 18 18:30:58 +0100 2008
2
2
 
3
- // Copyright (c) 2005-2007 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
3
+ // Copyright (c) 2005-2008 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
4
4
  //
5
5
  // script.aculo.us is freely distributable under the terms of an MIT-style license.
6
6
  // For details, see the script.aculo.us web site: http://script.aculo.us/
@@ -26,7 +26,7 @@ var Builder = {
26
26
  // due to a Firefox bug
27
27
  node: function(elementName) {
28
28
  elementName = elementName.toUpperCase();
29
-
29
+
30
30
  // try innerHTML approach
31
31
  var parentTag = this.NODEMAP[elementName] || 'div';
32
32
  var parentElement = document.createElement(parentTag);
@@ -34,14 +34,14 @@ var Builder = {
34
34
  parentElement.innerHTML = "<" + elementName + "></" + elementName + ">";
35
35
  } catch(e) {}
36
36
  var element = parentElement.firstChild || null;
37
-
37
+
38
38
  // see if browser added wrapping tags
39
39
  if(element && (element.tagName.toUpperCase() != elementName))
40
40
  element = element.getElementsByTagName(elementName)[0];
41
-
41
+
42
42
  // fallback to createElement approach
43
43
  if(!element) element = document.createElement(elementName);
44
-
44
+
45
45
  // abort if nothing could be created
46
46
  if(!element) return;
47
47
 
@@ -62,19 +62,19 @@ var Builder = {
62
62
  // workaround firefox 1.0.X bug
63
63
  if(!element) {
64
64
  element = document.createElement(elementName);
65
- for(attr in arguments[1])
65
+ for(attr in arguments[1])
66
66
  element[attr == 'class' ? 'className' : attr] = arguments[1][attr];
67
67
  }
68
68
  if(element.tagName.toUpperCase() != elementName)
69
69
  element = parentElement.getElementsByTagName(elementName)[0];
70
70
  }
71
- }
71
+ }
72
72
 
73
73
  // text, or array of children
74
74
  if(arguments[2])
75
75
  this._children(element, arguments[2]);
76
76
 
77
- return element;
77
+ return $(element);
78
78
  },
79
79
  _text: function(text) {
80
80
  return document.createTextNode(text);
@@ -100,7 +100,7 @@ var Builder = {
100
100
  if(typeof children=='object') { // array can hold nodes and text
101
101
  children.flatten().each( function(e) {
102
102
  if(typeof e=='object')
103
- element.appendChild(e)
103
+ element.appendChild(e);
104
104
  else
105
105
  if(Builder._isStringOrNumber(e))
106
106
  element.appendChild(Builder._text(e));
@@ -117,20 +117,20 @@ var Builder = {
117
117
  $(element).update(html.strip());
118
118
  return element.down();
119
119
  },
120
- dump: function(scope) {
121
- if(typeof scope != 'object' && typeof scope != 'function') scope = window; //global scope
122
-
120
+ dump: function(scope) {
121
+ if(typeof scope != 'object' && typeof scope != 'function') scope = window; //global scope
122
+
123
123
  var tags = ("A ABBR ACRONYM ADDRESS APPLET AREA B BASE BASEFONT BDO BIG BLOCKQUOTE BODY " +
124
124
  "BR BUTTON CAPTION CENTER CITE CODE COL COLGROUP DD DEL DFN DIR DIV DL DT EM FIELDSET " +
125
125
  "FONT FORM FRAME FRAMESET H1 H2 H3 H4 H5 H6 HEAD HR HTML I IFRAME IMG INPUT INS ISINDEX "+
126
126
  "KBD LABEL LEGEND LI LINK MAP MENU META NOFRAMES NOSCRIPT OBJECT OL OPTGROUP OPTION P "+
127
127
  "PARAM PRE Q S SAMP SCRIPT SELECT SMALL SPAN STRIKE STRONG STYLE SUB SUP TABLE TBODY TD "+
128
128
  "TEXTAREA TFOOT TH THEAD TITLE TR TT U UL VAR").split(/\s+/);
129
-
130
- tags.each( function(tag){
131
- scope[tag] = function() {
132
- return Builder.node.apply(Builder, [tag].concat($A(arguments)));
133
- }
129
+
130
+ tags.each( function(tag){
131
+ scope[tag] = function() {
132
+ return Builder.node.apply(Builder, [tag].concat($A(arguments)));
133
+ };
134
134
  });
135
135
  }
136
- }
136
+ };
@@ -1,24 +1,24 @@
1
- // script.aculo.us controls.js v1.8.1, Thu Jan 03 22:07:12 -0500 2008
1
+ // script.aculo.us controls.js v1.8.2, Tue Nov 18 18:30:58 +0100 2008
2
2
 
3
- // Copyright (c) 2005-2007 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
4
- // (c) 2005-2007 Ivan Krstic (http://blogs.law.harvard.edu/ivan)
5
- // (c) 2005-2007 Jon Tirsen (http://www.tirsen.com)
3
+ // Copyright (c) 2005-2008 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
4
+ // (c) 2005-2008 Ivan Krstic (http://blogs.law.harvard.edu/ivan)
5
+ // (c) 2005-2008 Jon Tirsen (http://www.tirsen.com)
6
6
  // Contributors:
7
7
  // Richard Livsey
8
8
  // Rahul Bhargava
9
9
  // Rob Wills
10
- //
10
+ //
11
11
  // script.aculo.us is freely distributable under the terms of an MIT-style license.
12
12
  // For details, see the script.aculo.us web site: http://script.aculo.us/
13
13
 
14
- // Autocompleter.Base handles all the autocompletion functionality
14
+ // Autocompleter.Base handles all the autocompletion functionality
15
15
  // that's independent of the data source for autocompletion. This
16
16
  // includes drawing the autocompletion menu, observing keyboard
17
17
  // and mouse events, and similar.
18
18
  //
19
- // Specific autocompleters need to provide, at the very least,
19
+ // Specific autocompleters need to provide, at the very least,
20
20
  // a getUpdatedChoices function that will be invoked every time
21
- // the text inside the monitored textbox changes. This method
21
+ // the text inside the monitored textbox changes. This method
22
22
  // should get the text for which to provide autocompletion by
23
23
  // invoking this.getToken(), NOT by directly accessing
24
24
  // this.element.value. This is to allow incremental tokenized
@@ -32,23 +32,23 @@
32
32
  // will incrementally autocomplete with a comma as the token.
33
33
  // Additionally, ',' in the above example can be replaced with
34
34
  // a token array, e.g. { tokens: [',', '\n'] } which
35
- // enables autocompletion on multiple tokens. This is most
36
- // useful when one of the tokens is \n (a newline), as it
35
+ // enables autocompletion on multiple tokens. This is most
36
+ // useful when one of the tokens is \n (a newline), as it
37
37
  // allows smart autocompletion after linebreaks.
38
38
 
39
39
  if(typeof Effect == 'undefined')
40
40
  throw("controls.js requires including script.aculo.us' effects.js library");
41
41
 
42
- var Autocompleter = { }
42
+ var Autocompleter = { };
43
43
  Autocompleter.Base = Class.create({
44
44
  baseInitialize: function(element, update, options) {
45
- element = $(element)
46
- this.element = element;
47
- this.update = $(update);
48
- this.hasFocus = false;
49
- this.changed = false;
50
- this.active = false;
51
- this.index = 0;
45
+ element = $(element);
46
+ this.element = element;
47
+ this.update = $(update);
48
+ this.hasFocus = false;
49
+ this.changed = false;
50
+ this.active = false;
51
+ this.index = 0;
52
52
  this.entryCount = 0;
53
53
  this.oldElementValue = this.element.value;
54
54
 
@@ -61,28 +61,28 @@ Autocompleter.Base = Class.create({
61
61
  this.options.tokens = this.options.tokens || [];
62
62
  this.options.frequency = this.options.frequency || 0.4;
63
63
  this.options.minChars = this.options.minChars || 1;
64
- this.options.onShow = this.options.onShow ||
65
- function(element, update){
64
+ this.options.onShow = this.options.onShow ||
65
+ function(element, update){
66
66
  if(!update.style.position || update.style.position=='absolute') {
67
67
  update.style.position = 'absolute';
68
68
  Position.clone(element, update, {
69
- setHeight: false,
69
+ setHeight: false,
70
70
  offsetTop: element.offsetHeight
71
71
  });
72
72
  }
73
73
  Effect.Appear(update,{duration:0.15});
74
74
  };
75
- this.options.onHide = this.options.onHide ||
75
+ this.options.onHide = this.options.onHide ||
76
76
  function(element, update){ new Effect.Fade(update,{duration:0.15}) };
77
77
 
78
- if(typeof(this.options.tokens) == 'string')
78
+ if(typeof(this.options.tokens) == 'string')
79
79
  this.options.tokens = new Array(this.options.tokens);
80
80
  // Force carriage returns as token delimiters anyway
81
81
  if (!this.options.tokens.include('\n'))
82
82
  this.options.tokens.push('\n');
83
83
 
84
84
  this.observer = null;
85
-
85
+
86
86
  this.element.setAttribute('autocomplete','off');
87
87
 
88
88
  Element.hide(this.update);
@@ -93,10 +93,10 @@ Autocompleter.Base = Class.create({
93
93
 
94
94
  show: function() {
95
95
  if(Element.getStyle(this.update, 'display')=='none') this.options.onShow(this.element, this.update);
96
- if(!this.iefix &&
96
+ if(!this.iefix &&
97
97
  (Prototype.Browser.IE) &&
98
98
  (Element.getStyle(this.update, 'position')=='absolute')) {
99
- new Insertion.After(this.update,
99
+ new Insertion.After(this.update,
100
100
  '<iframe id="' + this.update.id + '_iefix" '+
101
101
  'style="display:none;position:absolute;filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);" ' +
102
102
  'src="javascript:false;" frameborder="0" scrolling="no"></iframe>');
@@ -104,7 +104,7 @@ Autocompleter.Base = Class.create({
104
104
  }
105
105
  if(this.iefix) setTimeout(this.fixIEOverlapping.bind(this), 50);
106
106
  },
107
-
107
+
108
108
  fixIEOverlapping: function() {
109
109
  Position.clone(this.update, this.iefix, {setTop:(!this.update.style.height)});
110
110
  this.iefix.style.zIndex = 1;
@@ -152,15 +152,15 @@ Autocompleter.Base = Class.create({
152
152
  Event.stop(event);
153
153
  return;
154
154
  }
155
- else
156
- if(event.keyCode==Event.KEY_TAB || event.keyCode==Event.KEY_RETURN ||
155
+ else
156
+ if(event.keyCode==Event.KEY_TAB || event.keyCode==Event.KEY_RETURN ||
157
157
  (Prototype.Browser.WebKit > 0 && event.keyCode == 0)) return;
158
158
 
159
159
  this.changed = true;
160
160
  this.hasFocus = true;
161
161
 
162
162
  if(this.observer) clearTimeout(this.observer);
163
- this.observer =
163
+ this.observer =
164
164
  setTimeout(this.onObserverEvent.bind(this), this.options.frequency*1000);
165
165
  },
166
166
 
@@ -172,35 +172,35 @@ Autocompleter.Base = Class.create({
172
172
 
173
173
  onHover: function(event) {
174
174
  var element = Event.findElement(event, 'LI');
175
- if(this.index != element.autocompleteIndex)
175
+ if(this.index != element.autocompleteIndex)
176
176
  {
177
177
  this.index = element.autocompleteIndex;
178
178
  this.render();
179
179
  }
180
180
  Event.stop(event);
181
181
  },
182
-
182
+
183
183
  onClick: function(event) {
184
184
  var element = Event.findElement(event, 'LI');
185
185
  this.index = element.autocompleteIndex;
186
186
  this.selectEntry();
187
187
  this.hide();
188
188
  },
189
-
189
+
190
190
  onBlur: function(event) {
191
191
  // needed to make click events working
192
192
  setTimeout(this.hide.bind(this), 250);
193
193
  this.hasFocus = false;
194
- this.active = false;
195
- },
196
-
194
+ this.active = false;
195
+ },
196
+
197
197
  render: function() {
198
198
  if(this.entryCount > 0) {
199
199
  for (var i = 0; i < this.entryCount; i++)
200
- this.index==i ?
201
- Element.addClassName(this.getEntry(i),"selected") :
200
+ this.index==i ?
201
+ Element.addClassName(this.getEntry(i),"selected") :
202
202
  Element.removeClassName(this.getEntry(i),"selected");
203
- if(this.hasFocus) {
203
+ if(this.hasFocus) {
204
204
  this.show();
205
205
  this.active = true;
206
206
  }
@@ -209,27 +209,27 @@ Autocompleter.Base = Class.create({
209
209
  this.hide();
210
210
  }
211
211
  },
212
-
212
+
213
213
  markPrevious: function() {
214
- if(this.index > 0) this.index--
214
+ if(this.index > 0) this.index--;
215
215
  else this.index = this.entryCount-1;
216
216
  this.getEntry(this.index).scrollIntoView(true);
217
217
  },
218
-
218
+
219
219
  markNext: function() {
220
- if(this.index < this.entryCount-1) this.index++
220
+ if(this.index < this.entryCount-1) this.index++;
221
221
  else this.index = 0;
222
222
  this.getEntry(this.index).scrollIntoView(false);
223
223
  },
224
-
224
+
225
225
  getEntry: function(index) {
226
226
  return this.update.firstChild.childNodes[index];
227
227
  },
228
-
228
+
229
229
  getCurrentEntry: function() {
230
230
  return this.getEntry(this.index);
231
231
  },
232
-
232
+
233
233
  selectEntry: function() {
234
234
  this.active = false;
235
235
  this.updateElement(this.getCurrentEntry());
@@ -246,7 +246,7 @@ Autocompleter.Base = Class.create({
246
246
  if(nodes.length>0) value = Element.collectTextNodes(nodes[0], this.options.select);
247
247
  } else
248
248
  value = Element.collectTextNodesIgnoreClass(selectedElement, 'informal');
249
-
249
+
250
250
  var bounds = this.getTokenBounds();
251
251
  if (bounds[0] != -1) {
252
252
  var newValue = this.element.value.substr(0, bounds[0]);
@@ -259,7 +259,7 @@ Autocompleter.Base = Class.create({
259
259
  }
260
260
  this.oldElementValue = this.element.value;
261
261
  this.element.focus();
262
-
262
+
263
263
  if (this.options.afterUpdateElement)
264
264
  this.options.afterUpdateElement(this.element, selectedElement);
265
265
  },
@@ -271,20 +271,20 @@ Autocompleter.Base = Class.create({
271
271
  Element.cleanWhitespace(this.update.down());
272
272
 
273
273
  if(this.update.firstChild && this.update.down().childNodes) {
274
- this.entryCount =
274
+ this.entryCount =
275
275
  this.update.down().childNodes.length;
276
276
  for (var i = 0; i < this.entryCount; i++) {
277
277
  var entry = this.getEntry(i);
278
278
  entry.autocompleteIndex = i;
279
279
  this.addObservers(entry);
280
280
  }
281
- } else {
281
+ } else {
282
282
  this.entryCount = 0;
283
283
  }
284
284
 
285
285
  this.stopIndicator();
286
286
  this.index = 0;
287
-
287
+
288
288
  if(this.entryCount==1 && this.options.autoSelect) {
289
289
  this.selectEntry();
290
290
  this.hide();
@@ -300,7 +300,7 @@ Autocompleter.Base = Class.create({
300
300
  },
301
301
 
302
302
  onObserverEvent: function() {
303
- this.changed = false;
303
+ this.changed = false;
304
304
  this.tokenBounds = null;
305
305
  if(this.getToken().length>=this.options.minChars) {
306
306
  this.getUpdatedChoices();
@@ -353,16 +353,16 @@ Ajax.Autocompleter = Class.create(Autocompleter.Base, {
353
353
 
354
354
  getUpdatedChoices: function() {
355
355
  this.startIndicator();
356
-
357
- var entry = encodeURIComponent(this.options.paramName) + '=' +
356
+
357
+ var entry = encodeURIComponent(this.options.paramName) + '=' +
358
358
  encodeURIComponent(this.getToken());
359
359
 
360
360
  this.options.parameters = this.options.callback ?
361
361
  this.options.callback(this.element, entry) : entry;
362
362
 
363
- if(this.options.defaultParams)
363
+ if(this.options.defaultParams)
364
364
  this.options.parameters += '&' + this.options.defaultParams;
365
-
365
+
366
366
  new Ajax.Request(this.url, this.options);
367
367
  },
368
368
 
@@ -384,7 +384,7 @@ Ajax.Autocompleter = Class.create(Autocompleter.Base, {
384
384
  // - choices - How many autocompletion choices to offer
385
385
  //
386
386
  // - partialSearch - If false, the autocompleter will match entered
387
- // text only at the beginning of strings in the
387
+ // text only at the beginning of strings in the
388
388
  // autocomplete array. Defaults to true, which will
389
389
  // match text at the beginning of any *word* in the
390
390
  // strings in the autocomplete array. If you want to
@@ -401,7 +401,7 @@ Ajax.Autocompleter = Class.create(Autocompleter.Base, {
401
401
  // - ignoreCase - Whether to ignore case when autocompleting.
402
402
  // Defaults to true.
403
403
  //
404
- // It's possible to pass in a custom function as the 'selector'
404
+ // It's possible to pass in a custom function as the 'selector'
405
405
  // option, if you prefer to write your own autocompletion logic.
406
406
  // In that case, the other options above will not apply unless
407
407
  // you support them.
@@ -429,20 +429,20 @@ Autocompleter.Local = Class.create(Autocompleter.Base, {
429
429
  var entry = instance.getToken();
430
430
  var count = 0;
431
431
 
432
- for (var i = 0; i < instance.options.array.length &&
433
- ret.length < instance.options.choices ; i++) {
432
+ for (var i = 0; i < instance.options.array.length &&
433
+ ret.length < instance.options.choices ; i++) {
434
434
 
435
435
  var elem = instance.options.array[i];
436
- var foundPos = instance.options.ignoreCase ?
437
- elem.toLowerCase().indexOf(entry.toLowerCase()) :
436
+ var foundPos = instance.options.ignoreCase ?
437
+ elem.toLowerCase().indexOf(entry.toLowerCase()) :
438
438
  elem.indexOf(entry);
439
439
 
440
440
  while (foundPos != -1) {
441
- if (foundPos == 0 && elem.length != entry.length) {
442
- ret.push("<li><strong>" + elem.substr(0, entry.length) + "</strong>" +
441
+ if (foundPos == 0 && elem.length != entry.length) {
442
+ ret.push("<li><strong>" + elem.substr(0, entry.length) + "</strong>" +
443
443
  elem.substr(entry.length) + "</li>");
444
444
  break;
445
- } else if (entry.length >= instance.options.partialChars &&
445
+ } else if (entry.length >= instance.options.partialChars &&
446
446
  instance.options.partialSearch && foundPos != -1) {
447
447
  if (instance.options.fullSearch || /\s/.test(elem.substr(foundPos-1,1))) {
448
448
  partial.push("<li>" + elem.substr(0, foundPos) + "<strong>" +
@@ -452,14 +452,14 @@ Autocompleter.Local = Class.create(Autocompleter.Base, {
452
452
  }
453
453
  }
454
454
 
455
- foundPos = instance.options.ignoreCase ?
456
- elem.toLowerCase().indexOf(entry.toLowerCase(), foundPos + 1) :
455
+ foundPos = instance.options.ignoreCase ?
456
+ elem.toLowerCase().indexOf(entry.toLowerCase(), foundPos + 1) :
457
457
  elem.indexOf(entry, foundPos + 1);
458
458
 
459
459
  }
460
460
  }
461
461
  if (partial.length)
462
- ret = ret.concat(partial.slice(0, instance.options.choices - ret.length))
462
+ ret = ret.concat(partial.slice(0, instance.options.choices - ret.length));
463
463
  return "<ul>" + ret.join('') + "</ul>";
464
464
  }
465
465
  }, options || { });
@@ -476,7 +476,7 @@ Field.scrollFreeActivate = function(field) {
476
476
  setTimeout(function() {
477
477
  Field.activate(field);
478
478
  }, 1);
479
- }
479
+ };
480
480
 
481
481
  Ajax.InPlaceEditor = Class.create({
482
482
  initialize: function(element, url, options) {
@@ -606,7 +606,7 @@ Ajax.InPlaceEditor = Class.create({
606
606
  this.triggerCallback('onEnterHover');
607
607
  },
608
608
  getText: function() {
609
- return this.element.innerHTML;
609
+ return this.element.innerHTML.unescapeHTML();
610
610
  },
611
611
  handleAJAXFailure: function(transport) {
612
612
  this.triggerCallback('onFailure', transport);
@@ -782,7 +782,7 @@ Ajax.InPlaceCollectionEditor = Class.create(Ajax.InPlaceEditor, {
782
782
  onSuccess: function(transport) {
783
783
  var js = transport.responseText.strip();
784
784
  if (!/^\[.*\]$/.test(js)) // TODO: improve sanity check
785
- throw 'Server returned an invalid collection representation.';
785
+ throw('Server returned an invalid collection representation.');
786
786
  this._collection = eval(js);
787
787
  this.checkForExternalText();
788
788
  }.bind(this),
@@ -939,7 +939,7 @@ Ajax.InPlaceCollectionEditor.DefaultOptions = {
939
939
  loadingCollectionText: 'Loading options...'
940
940
  };
941
941
 
942
- // Delayed observer, like Form.Element.Observer,
942
+ // Delayed observer, like Form.Element.Observer,
943
943
  // but waits for delay after last key input
944
944
  // Ideal for live-search fields
945
945
 
@@ -949,7 +949,7 @@ Form.Element.DelayedObserver = Class.create({
949
949
  this.element = $(element);
950
950
  this.callback = callback;
951
951
  this.timer = null;
952
- this.lastValue = $F(this.element);
952
+ this.lastValue = $F(this.element);
953
953
  Event.observe(this.element,'keyup',this.delayedListener.bindAsEventListener(this));
954
954
  },
955
955
  delayedListener: function(event) {
@@ -962,4 +962,4 @@ Form.Element.DelayedObserver = Class.create({
962
962
  this.timer = null;
963
963
  this.callback(this.element, $F(this.element));
964
964
  }
965
- });
965
+ });