Permalink
Browse files

Initial models and controllers, no tests

  • Loading branch information...
1 parent d7faffa commit 7923be90b5674b3d88dd96948e038d6cb65076e6 @rwdaigle rwdaigle committed Apr 1, 2009
Showing with 24,056 additions and 0 deletions.
  1. +6 −0 .gitignore
  2. +243 −0 README
  3. +10 −0 Rakefile
  4. +40 −0 app/controllers/api/api_controller.rb
  5. +30 −0 app/controllers/api/v1/statements_controller.rb
  6. +6 −0 app/controllers/api/v1/v1_controller.rb
  7. +8 −0 app/controllers/application_controller.rb
  8. +30 −0 app/helpers/application_helper.rb
  9. +16 −0 app/models/application.rb
  10. +14 −0 app/models/statement.rb
  11. +110 −0 config/boot.rb
  12. +46 −0 config/environment.rb
  13. +17 −0 config/environments/development.rb
  14. +28 −0 config/environments/production.rb
  15. +28 −0 config/environments/test.rb
  16. +7 −0 config/initializers/backtrace_silencers.rb
  17. +3 −0 config/initializers/exception_notifications.rb
  18. +10 −0 config/initializers/inflections.rb
  19. +5 −0 config/initializers/mime_types.rb
  20. +19 −0 config/initializers/new_rails_defaults.rb
  21. +15 −0 config/initializers/session_store.rb
  22. +1 −0 config/initializers/will_paginate.rb
  23. +5 −0 config/locales/en.yml
  24. +145 −0 config/newrelic.yml
  25. +9 −0 config/routes.rb
  26. +27 −0 db/migrate/20090401132240_initial_release.rb
  27. +2 −0 doc/README_FOR_APP
  28. +4 −0 lib/tasks/db.rake
  29. +165 −0 lib/tasks/rspec.rake
  30. +30 −0 public/404.html
  31. +30 −0 public/422.html
  32. +30 −0 public/500.html
  33. 0 public/favicon.ico
  34. BIN public/images/rails.png
  35. +275 −0 public/index.html
  36. +2 −0 public/javascripts/application.js
  37. +963 −0 public/javascripts/controls.js
  38. +973 −0 public/javascripts/dragdrop.js
  39. +1,128 −0 public/javascripts/effects.js
  40. +4,320 −0 public/javascripts/prototype.js
  41. +5 −0 public/robots.txt
  42. +4 −0 script/about
  43. +6 −0 script/autospec
  44. +3 −0 script/console
  45. +3 −0 script/dbconsole
  46. +3 −0 script/destroy
  47. +3 −0 script/generate
  48. +3 −0 script/performance/benchmarker
  49. +3 −0 script/performance/profiler
  50. +3 −0 script/plugin
  51. +3 −0 script/runner
  52. +3 −0 script/server
  53. +10 −0 script/spec
  54. +9 −0 script/spec_server
  55. +2 −0 spec/rcov.opts
  56. +4 −0 spec/spec.opts
  57. +47 −0 spec/spec_helper.rb
  58. +267 −0 vendor/gems/haml-2.1.0/.specification
  59. +138 −0 vendor/gems/haml-2.1.0/FAQ
  60. +20 −0 vendor/gems/haml-2.1.0/MIT-LICENSE
  61. +325 −0 vendor/gems/haml-2.1.0/README.rdoc
  62. +1 −0 vendor/gems/haml-2.1.0/REVISION
  63. +150 −0 vendor/gems/haml-2.1.0/Rakefile
  64. +1 −0 vendor/gems/haml-2.1.0/VERSION
  65. +7 −0 vendor/gems/haml-2.1.0/bin/css2sass
  66. +9 −0 vendor/gems/haml-2.1.0/bin/haml
  67. +7 −0 vendor/gems/haml-2.1.0/bin/html2haml
  68. +8 −0 vendor/gems/haml-2.1.0/bin/sass
  69. +434 −0 vendor/gems/haml-2.1.0/extra/haml-mode.el
  70. +98 −0 vendor/gems/haml-2.1.0/extra/sass-mode.el
  71. +8 −0 vendor/gems/haml-2.1.0/init.rb
  72. +1,064 −0 vendor/gems/haml-2.1.0/lib/haml.rb
  73. +255 −0 vendor/gems/haml-2.1.0/lib/haml/buffer.rb
  74. +268 −0 vendor/gems/haml-2.1.0/lib/haml/engine.rb
  75. +22 −0 vendor/gems/haml-2.1.0/lib/haml/error.rb
  76. +395 −0 vendor/gems/haml-2.1.0/lib/haml/exec.rb
  77. +275 −0 vendor/gems/haml-2.1.0/lib/haml/filters.rb
  78. +466 −0 vendor/gems/haml-2.1.0/lib/haml/helpers.rb
  79. +45 −0 vendor/gems/haml-2.1.0/lib/haml/helpers/action_view_extensions.rb
  80. +181 −0 vendor/gems/haml-2.1.0/lib/haml/helpers/action_view_mods.rb
  81. +222 −0 vendor/gems/haml-2.1.0/lib/haml/html.rb
  82. +867 −0 vendor/gems/haml-2.1.0/lib/haml/precompiler.rb
  83. +45 −0 vendor/gems/haml-2.1.0/lib/haml/shared.rb
  84. +51 −0 vendor/gems/haml-2.1.0/lib/haml/template.rb
  85. +58 −0 vendor/gems/haml-2.1.0/lib/haml/template/patch.rb
  86. +72 −0 vendor/gems/haml-2.1.0/lib/haml/template/plugin.rb
  87. +77 −0 vendor/gems/haml-2.1.0/lib/haml/util.rb
  88. +973 −0 vendor/gems/haml-2.1.0/lib/sass.rb
  89. +388 −0 vendor/gems/haml-2.1.0/lib/sass/css.rb
  90. +501 −0 vendor/gems/haml-2.1.0/lib/sass/engine.rb
  91. +33 −0 vendor/gems/haml-2.1.0/lib/sass/environment.rb
  92. +35 −0 vendor/gems/haml-2.1.0/lib/sass/error.rb
  93. +203 −0 vendor/gems/haml-2.1.0/lib/sass/plugin.rb
  94. +56 −0 vendor/gems/haml-2.1.0/lib/sass/plugin/merb.rb
  95. +24 −0 vendor/gems/haml-2.1.0/lib/sass/plugin/rails.rb
  96. +44 −0 vendor/gems/haml-2.1.0/lib/sass/repl.rb
  97. +38 −0 vendor/gems/haml-2.1.0/lib/sass/script.rb
  98. +13 −0 vendor/gems/haml-2.1.0/lib/sass/script/bool.rb
  99. +97 −0 vendor/gems/haml-2.1.0/lib/sass/script/color.rb
  100. +28 −0 vendor/gems/haml-2.1.0/lib/sass/script/funcall.rb
  101. +100 −0 vendor/gems/haml-2.1.0/lib/sass/script/functions.rb
  102. +144 −0 vendor/gems/haml-2.1.0/lib/sass/script/lexer.rb
  103. +60 −0 vendor/gems/haml-2.1.0/lib/sass/script/literal.rb
  104. +231 −0 vendor/gems/haml-2.1.0/lib/sass/script/number.rb
  105. +30 −0 vendor/gems/haml-2.1.0/lib/sass/script/operation.rb
  106. +142 −0 vendor/gems/haml-2.1.0/lib/sass/script/parser.rb
  107. +42 −0 vendor/gems/haml-2.1.0/lib/sass/script/string.rb
  108. +21 −0 vendor/gems/haml-2.1.0/lib/sass/script/unary_operation.rb
  109. +20 −0 vendor/gems/haml-2.1.0/lib/sass/script/variable.rb
  110. +60 −0 vendor/gems/haml-2.1.0/lib/sass/tree/attr_node.rb
  111. +26 −0 vendor/gems/haml-2.1.0/lib/sass/tree/comment_node.rb
  112. +22 −0 vendor/gems/haml-2.1.0/lib/sass/tree/debug_node.rb
  113. +50 −0 vendor/gems/haml-2.1.0/lib/sass/tree/directive_node.rb
  114. +27 −0 vendor/gems/haml-2.1.0/lib/sass/tree/file_node.rb
  115. +29 −0 vendor/gems/haml-2.1.0/lib/sass/tree/for_node.rb
  116. +27 −0 vendor/gems/haml-2.1.0/lib/sass/tree/if_node.rb
  117. +18 −0 vendor/gems/haml-2.1.0/lib/sass/tree/mixin_def_node.rb
  118. +34 −0 vendor/gems/haml-2.1.0/lib/sass/tree/mixin_node.rb
  119. +93 −0 vendor/gems/haml-2.1.0/lib/sass/tree/node.rb
  120. +116 −0 vendor/gems/haml-2.1.0/lib/sass/tree/rule_node.rb
  121. +24 −0 vendor/gems/haml-2.1.0/lib/sass/tree/variable_node.rb
  122. +20 −0 vendor/gems/haml-2.1.0/lib/sass/tree/while_node.rb
  123. +1 −0 vendor/gems/haml-2.1.0/rails/init.rb
  124. +99 −0 vendor/gems/haml-2.1.0/test/benchmark.rb
  125. +698 −0 vendor/gems/haml-2.1.0/test/haml/engine_test.rb
  126. +225 −0 vendor/gems/haml-2.1.0/test/haml/helper_test.rb
  127. +92 −0 vendor/gems/haml-2.1.0/test/haml/html2haml_test.rb
  128. +52 −0 vendor/gems/haml-2.1.0/test/haml/markaby/standard.mab
  129. +6 −0 vendor/gems/haml-2.1.0/test/haml/mocks/article.rb
  130. +15 −0 vendor/gems/haml-2.1.0/test/haml/results/content_for_layout.xhtml
  131. +9 −0 vendor/gems/haml-2.1.0/test/haml/results/eval_suppressed.xhtml
  132. +67 −0 vendor/gems/haml-2.1.0/test/haml/results/filters.xhtml
  133. +93 −0 vendor/gems/haml-2.1.0/test/haml/results/helpers.xhtml
  134. +10 −0 vendor/gems/haml-2.1.0/test/haml/results/helpful.xhtml
  135. +68 −0 vendor/gems/haml-2.1.0/test/haml/results/just_stuff.xhtml
  136. +12 −0 vendor/gems/haml-2.1.0/test/haml/results/list.xhtml
  137. +40 −0 vendor/gems/haml-2.1.0/test/haml/results/nuke_inner_whitespace.xhtml
  138. +148 −0 vendor/gems/haml-2.1.0/test/haml/results/nuke_outer_whitespace.xhtml
  139. +20 −0 vendor/gems/haml-2.1.0/test/haml/results/original_engine.xhtml
  140. +5 −0 vendor/gems/haml-2.1.0/test/haml/results/partial_layout.xhtml
  141. +21 −0 vendor/gems/haml-2.1.0/test/haml/results/partials.xhtml
  142. +74 −0 vendor/gems/haml-2.1.0/test/haml/results/silent_script.xhtml
  143. +42 −0 vendor/gems/haml-2.1.0/test/haml/results/standard.xhtml
  144. +23 −0 vendor/gems/haml-2.1.0/test/haml/results/tag_parsing.xhtml
  145. +5 −0 vendor/gems/haml-2.1.0/test/haml/results/very_basic.xhtml
  146. +86 −0 vendor/gems/haml-2.1.0/test/haml/results/whitespace_handling.xhtml
  147. +12 −0 vendor/gems/haml-2.1.0/test/haml/rhtml/_av_partial_1.rhtml
  148. +8 −0 vendor/gems/haml-2.1.0/test/haml/rhtml/_av_partial_2.rhtml
  149. +62 −0 vendor/gems/haml-2.1.0/test/haml/rhtml/action_view.rhtml
  150. +54 −0 vendor/gems/haml-2.1.0/test/haml/rhtml/standard.rhtml
  151. +185 −0 vendor/gems/haml-2.1.0/test/haml/template_test.rb
  152. +9 −0 vendor/gems/haml-2.1.0/test/haml/templates/_av_partial_1.haml
  153. +9 −0 vendor/gems/haml-2.1.0/test/haml/templates/_av_partial_1_ugly.haml
  154. +5 −0 vendor/gems/haml-2.1.0/test/haml/templates/_av_partial_2.haml
  155. +5 −0 vendor/gems/haml-2.1.0/test/haml/templates/_av_partial_2_ugly.haml
  156. +3 −0 vendor/gems/haml-2.1.0/test/haml/templates/_layout_for_partial.haml
  157. +8 −0 vendor/gems/haml-2.1.0/test/haml/templates/_partial.haml
  158. +3 −0 vendor/gems/haml-2.1.0/test/haml/templates/_text_area.haml
  159. +47 −0 vendor/gems/haml-2.1.0/test/haml/templates/action_view.haml
  160. +47 −0 vendor/gems/haml-2.1.0/test/haml/templates/action_view_ugly.haml
  161. +8 −0 vendor/gems/haml-2.1.0/test/haml/templates/breakage.haml
  162. +10 −0 vendor/gems/haml-2.1.0/test/haml/templates/content_for_layout.haml
  163. +11 −0 vendor/gems/haml-2.1.0/test/haml/templates/eval_suppressed.haml
  164. +71 −0 vendor/gems/haml-2.1.0/test/haml/templates/filters.haml
  165. +95 −0 vendor/gems/haml-2.1.0/test/haml/templates/helpers.haml
  166. +11 −0 vendor/gems/haml-2.1.0/test/haml/templates/helpful.haml
  167. +83 −0 vendor/gems/haml-2.1.0/test/haml/templates/just_stuff.haml
  168. +12 −0 vendor/gems/haml-2.1.0/test/haml/templates/list.haml
  169. +32 −0 vendor/gems/haml-2.1.0/test/haml/templates/nuke_inner_whitespace.haml
  170. +144 −0 vendor/gems/haml-2.1.0/test/haml/templates/nuke_outer_whitespace.haml
  171. +17 −0 vendor/gems/haml-2.1.0/test/haml/templates/original_engine.haml
  172. +3 −0 vendor/gems/haml-2.1.0/test/haml/templates/partial_layout.haml
  173. +1 −0 vendor/gems/haml-2.1.0/test/haml/templates/partialize.haml
  174. +12 −0 vendor/gems/haml-2.1.0/test/haml/templates/partials.haml
  175. +40 −0 vendor/gems/haml-2.1.0/test/haml/templates/silent_script.haml
  176. +42 −0 vendor/gems/haml-2.1.0/test/haml/templates/standard.haml
  177. +42 −0 vendor/gems/haml-2.1.0/test/haml/templates/standard_ugly.haml
  178. +21 −0 vendor/gems/haml-2.1.0/test/haml/templates/tag_parsing.haml
  179. +4 −0 vendor/gems/haml-2.1.0/test/haml/templates/very_basic.haml
  180. +87 −0 vendor/gems/haml-2.1.0/test/haml/templates/whitespace_handling.haml
  181. +12 −0 vendor/gems/haml-2.1.0/test/linked_rails.rb
  182. +752 −0 vendor/gems/haml-2.1.0/test/sass/engine_test.rb
  183. +96 −0 vendor/gems/haml-2.1.0/test/sass/functions_test.rb
  184. +9 −0 vendor/gems/haml-2.1.0/test/sass/more_results/more1.css
  185. +26 −0 vendor/gems/haml-2.1.0/test/sass/more_results/more1_with_line_comments.css
  186. +29 −0 vendor/gems/haml-2.1.0/test/sass/more_results/more_import.css
  187. +2 −0 vendor/gems/haml-2.1.0/test/sass/more_templates/_more_partial.sass
  188. +23 −0 vendor/gems/haml-2.1.0/test/sass/more_templates/more1.sass
  189. +11 −0 vendor/gems/haml-2.1.0/test/sass/more_templates/more_import.sass
  190. +208 −0 vendor/gems/haml-2.1.0/test/sass/plugin_test.rb
  191. +4 −0 vendor/gems/haml-2.1.0/test/sass/results/alt.css
  192. +9 −0 vendor/gems/haml-2.1.0/test/sass/results/basic.css
  193. +5 −0 vendor/gems/haml-2.1.0/test/sass/results/compact.css
  194. +87 −0 vendor/gems/haml-2.1.0/test/sass/results/complex.css
  195. +1 −0 vendor/gems/haml-2.1.0/test/sass/results/compressed.css
  196. +19 −0 vendor/gems/haml-2.1.0/test/sass/results/expanded.css
  197. +29 −0 vendor/gems/haml-2.1.0/test/sass/results/import.css
  198. +49 −0 vendor/gems/haml-2.1.0/test/sass/results/line_numbers.css
  199. +95 −0 vendor/gems/haml-2.1.0/test/sass/results/mixins.css
  200. +24 −0 vendor/gems/haml-2.1.0/test/sass/results/multiline.css
  201. +22 −0 vendor/gems/haml-2.1.0/test/sass/results/nested.css
  202. +13 −0 vendor/gems/haml-2.1.0/test/sass/results/parent_ref.css
  203. +16 −0 vendor/gems/haml-2.1.0/test/sass/results/script.css
  204. +1 −0 vendor/gems/haml-2.1.0/test/sass/results/subdir/nested_subdir/nested_subdir.css
  205. +3 −0 vendor/gems/haml-2.1.0/test/sass/results/subdir/subdir.css
  206. +11 −0 vendor/gems/haml-2.1.0/test/sass/results/units.css
  207. +152 −0 vendor/gems/haml-2.1.0/test/sass/script_test.rb
  208. +2 −0 vendor/gems/haml-2.1.0/test/sass/templates/_partial.sass
  209. +16 −0 vendor/gems/haml-2.1.0/test/sass/templates/alt.sass
  210. +23 −0 vendor/gems/haml-2.1.0/test/sass/templates/basic.sass
  211. +2 −0 vendor/gems/haml-2.1.0/test/sass/templates/bork.sass
  212. +2 −0 vendor/gems/haml-2.1.0/test/sass/templates/bork2.sass
  213. +17 −0 vendor/gems/haml-2.1.0/test/sass/templates/compact.sass
  214. +309 −0 vendor/gems/haml-2.1.0/test/sass/templates/complex.sass
  215. +15 −0 vendor/gems/haml-2.1.0/test/sass/templates/compressed.sass
  216. +17 −0 vendor/gems/haml-2.1.0/test/sass/templates/expanded.sass
  217. +11 −0 vendor/gems/haml-2.1.0/test/sass/templates/import.sass
  218. +19 −0 vendor/gems/haml-2.1.0/test/sass/templates/importee.sass
  219. +13 −0 vendor/gems/haml-2.1.0/test/sass/templates/line_numbers.sass
  220. +76 −0 vendor/gems/haml-2.1.0/test/sass/templates/mixins.sass
  221. +20 −0 vendor/gems/haml-2.1.0/test/sass/templates/multiline.sass
  222. +25 −0 vendor/gems/haml-2.1.0/test/sass/templates/nested.sass
  223. +25 −0 vendor/gems/haml-2.1.0/test/sass/templates/parent_ref.sass
  224. +101 −0 vendor/gems/haml-2.1.0/test/sass/templates/script.sass
  225. +2 −0 vendor/gems/haml-2.1.0/test/sass/templates/subdir/nested_subdir/_nested_partial.sass
  226. +3 −0 vendor/gems/haml-2.1.0/test/sass/templates/subdir/nested_subdir/nested_subdir.sass
  227. +6 −0 vendor/gems/haml-2.1.0/test/sass/templates/subdir/subdir.sass
  228. +11 −0 vendor/gems/haml-2.1.0/test/sass/templates/units.sass
Sorry, we could not display the entire diff because too many files (2,986) changed.
View
6 .gitignore
@@ -0,0 +1,6 @@
+.DS_Store
+log/*.log
+tmp
+config/database.yml
+db/*.sqlite3
+*.tmproj
View
243 README
@@ -0,0 +1,243 @@
+== Welcome to Rails
+
+Rails is a web-application framework that includes everything needed to create
+database-backed web applications according to the Model-View-Control pattern.
+
+This pattern splits the view (also called the presentation) into "dumb" templates
+that are primarily responsible for inserting pre-built data in between HTML tags.
+The model contains the "smart" domain objects (such as Account, Product, Person,
+Post) that holds all the business logic and knows how to persist themselves to
+a database. The controller handles the incoming requests (such as Save New Account,
+Update Product, Show Post) by manipulating the model and directing data to the view.
+
+In Rails, the model is handled by what's called an object-relational mapping
+layer entitled Active Record. This layer allows you to present the data from
+database rows as objects and embellish these data objects with business logic
+methods. You can read more about Active Record in
+link:files/vendor/rails/activerecord/README.html.
+
+The controller and view are handled by the Action Pack, which handles both
+layers by its two parts: Action View and Action Controller. These two layers
+are bundled in a single package due to their heavy interdependence. This is
+unlike the relationship between the Active Record and Action Pack that is much
+more separate. Each of these packages can be used independently outside of
+Rails. You can read more about Action Pack in
+link:files/vendor/rails/actionpack/README.html.
+
+
+== Getting Started
+
+1. At the command prompt, start a new Rails application using the <tt>rails</tt> command
+ and your application name. Ex: rails myapp
+2. Change directory into myapp and start the web server: <tt>script/server</tt> (run with --help for options)
+3. Go to http://localhost:3000/ and get "Welcome aboard: You're riding the Rails!"
+4. Follow the guidelines to start developing your application
+
+
+== Web Servers
+
+By default, Rails will try to use Mongrel if it's are installed when started with script/server, otherwise Rails will use WEBrick, the webserver that ships with Ruby. But you can also use Rails
+with a variety of other web servers.
+
+Mongrel is a Ruby-based webserver with a C component (which requires compilation) that is
+suitable for development and deployment of Rails applications. If you have Ruby Gems installed,
+getting up and running with mongrel is as easy as: <tt>gem install mongrel</tt>.
+More info at: http://mongrel.rubyforge.org
+
+Say other Ruby web servers like Thin and Ebb or regular web servers like Apache or LiteSpeed or
+Lighttpd or IIS. The Ruby web servers are run through Rack and the latter can either be setup to use
+FCGI or proxy to a pack of Mongrels/Thin/Ebb servers.
+
+== Apache .htaccess example for FCGI/CGI
+
+# General Apache options
+AddHandler fastcgi-script .fcgi
+AddHandler cgi-script .cgi
+Options +FollowSymLinks +ExecCGI
+
+# If you don't want Rails to look in certain directories,
+# use the following rewrite rules so that Apache won't rewrite certain requests
+#
+# Example:
+# RewriteCond %{REQUEST_URI} ^/notrails.*
+# RewriteRule .* - [L]
+
+# Redirect all requests not available on the filesystem to Rails
+# By default the cgi dispatcher is used which is very slow
+#
+# For better performance replace the dispatcher with the fastcgi one
+#
+# Example:
+# RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
+RewriteEngine On
+
+# If your Rails application is accessed via an Alias directive,
+# then you MUST also set the RewriteBase in this htaccess file.
+#
+# Example:
+# Alias /myrailsapp /path/to/myrailsapp/public
+# RewriteBase /myrailsapp
+
+RewriteRule ^$ index.html [QSA]
+RewriteRule ^([^.]+)$ $1.html [QSA]
+RewriteCond %{REQUEST_FILENAME} !-f
+RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
+
+# In case Rails experiences terminal errors
+# Instead of displaying this message you can supply a file here which will be rendered instead
+#
+# Example:
+# ErrorDocument 500 /500.html
+
+ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly"
+
+
+== Debugging Rails
+
+Sometimes your application goes wrong. Fortunately there are a lot of tools that
+will help you debug it and get it back on the rails.
+
+First area to check is the application log files. Have "tail -f" commands running
+on the server.log and development.log. Rails will automatically display debugging
+and runtime information to these files. Debugging info will also be shown in the
+browser on requests from 127.0.0.1.
+
+You can also log your own messages directly into the log file from your code using
+the Ruby logger class from inside your controllers. Example:
+
+ class WeblogController < ActionController::Base
+ def destroy
+ @weblog = Weblog.find(params[:id])
+ @weblog.destroy
+ logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
+ end
+ end
+
+The result will be a message in your log file along the lines of:
+
+ Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1
+
+More information on how to use the logger is at http://www.ruby-doc.org/core/
+
+Also, Ruby documentation can be found at http://www.ruby-lang.org/ including:
+
+* The Learning Ruby (Pickaxe) Book: http://www.ruby-doc.org/docs/ProgrammingRuby/
+* Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
+
+These two online (and free) books will bring you up to speed on the Ruby language
+and also on programming in general.
+
+
+== Debugger
+
+Debugger support is available through the debugger command when you start your Mongrel or
+Webrick server with --debugger. This means that you can break out of execution at any point
+in the code, investigate and change the model, AND then resume execution!
+You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'
+Example:
+
+ class WeblogController < ActionController::Base
+ def index
+ @posts = Post.find(:all)
+ debugger
+ end
+ end
+
+So the controller will accept the action, run the first line, then present you
+with a IRB prompt in the server window. Here you can do things like:
+
+ >> @posts.inspect
+ => "[#<Post:0x14a6be8 @attributes={\"title\"=>nil, \"body\"=>nil, \"id\"=>\"1\"}>,
+ #<Post:0x14a6620 @attributes={\"title\"=>\"Rails you know!\", \"body\"=>\"Only ten..\", \"id\"=>\"2\"}>]"
+ >> @posts.first.title = "hello from a debugger"
+ => "hello from a debugger"
+
+...and even better is that you can examine how your runtime objects actually work:
+
+ >> f = @posts.first
+ => #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
+ >> f.
+ Display all 152 possibilities? (y or n)
+
+Finally, when you're ready to resume execution, you enter "cont"
+
+
+== Console
+
+You can interact with the domain model by starting the console through <tt>script/console</tt>.
+Here you'll have all parts of the application configured, just like it is when the
+application is running. You can inspect domain models, change values, and save to the
+database. Starting the script without arguments will launch it in the development environment.
+Passing an argument will specify a different environment, like <tt>script/console production</tt>.
+
+To reload your controllers and models after launching the console run <tt>reload!</tt>
+
+== dbconsole
+
+You can go to the command line of your database directly through <tt>script/dbconsole</tt>.
+You would be connected to the database with the credentials defined in database.yml.
+Starting the script without arguments will connect you to the development database. Passing an
+argument will connect you to a different database, like <tt>script/dbconsole production</tt>.
+Currently works for mysql, postgresql and sqlite.
+
+== Description of Contents
+
+app
+ Holds all the code that's specific to this particular application.
+
+app/controllers
+ Holds controllers that should be named like weblogs_controller.rb for
+ automated URL mapping. All controllers should descend from ApplicationController
+ which itself descends from ActionController::Base.
+
+app/models
+ Holds models that should be named like post.rb.
+ Most models will descend from ActiveRecord::Base.
+
+app/views
+ Holds the template files for the view that should be named like
+ weblogs/index.html.erb for the WeblogsController#index action. All views use eRuby
+ syntax.
+
+app/views/layouts
+ Holds the template files for layouts to be used with views. This models the common
+ header/footer method of wrapping views. In your views, define a layout using the
+ <tt>layout :default</tt> and create a file named default.html.erb. Inside default.html.erb,
+ call <% yield %> to render the view using this layout.
+
+app/helpers
+ Holds view helpers that should be named like weblogs_helper.rb. These are generated
+ for you automatically when using script/generate for controllers. Helpers can be used to
+ wrap functionality for your views into methods.
+
+config
+ Configuration files for the Rails environment, the routing map, the database, and other dependencies.
+
+db
+ Contains the database schema in schema.rb. db/migrate contains all
+ the sequence of Migrations for your schema.
+
+doc
+ This directory is where your application documentation will be stored when generated
+ using <tt>rake doc:app</tt>
+
+lib
+ Application specific libraries. Basically, any kind of custom code that doesn't
+ belong under controllers, models, or helpers. This directory is in the load path.
+
+public
+ The directory available for the web server. Contains subdirectories for images, stylesheets,
+ and javascripts. Also contains the dispatchers and the default HTML files. This should be
+ set as the DOCUMENT_ROOT of your web server.
+
+script
+ Helper scripts for automation and generation.
+
+test
+ Unit and functional tests along with fixtures. When using the script/generate scripts, template
+ test files will be generated for you and placed in this directory.
+
+vendor
+ External libraries that the application depends on. Also includes the plugins subdirectory.
+ If the app has frozen rails, those gems also go here, under vendor/rails/.
+ This directory is in the load path.
View
10 Rakefile
@@ -0,0 +1,10 @@
+# Add your own tasks in files placed in lib/tasks ending in .rake,
+# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
+
+require(File.join(File.dirname(__FILE__), 'config', 'boot'))
+
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+
+require 'tasks/rails'
View
40 app/controllers/api/api_controller.rb
@@ -0,0 +1,40 @@
+module Api
+ class ApiController < ApplicationController
+
+ # Turn off CSR/forgery protection
+ skip_before_filter :verify_authenticity_token
+
+ # All API requests must be authenticated
+ before_filter :basic_app_authenticate, :require_app_authentication
+
+ #-- Authentication/Authorization helpers
+
+ def current_app
+ @application
+ end
+
+ def current_device_id
+ @device_id
+ end
+
+ def basic_app_authenticate
+ authenticate_or_request_with_http_basic("Remote Logger API") do |device_id, app_token|
+ @application = Application.find_by_token(app_token)
+ @device_id = device_id
+ end
+ end
+
+ #-- Authentication/Authorization filters
+
+ def require_app_authentication
+ if !current_app or !current_device_id
+ respond_to do |wants|
+ message = 'Application token or device identifier were missing and/or invalid'
+ wants.html { render :text => message, :status => 401 }
+ wants.xml { render :xml => { :errors => { :error => message }}, :status => 401 }
+ wants.json { render :json => { :errors => { :error => message }}, :status => 401 }
+ end
+ end
+ end
+ end
+end
View
30 app/controllers/api/v1/statements_controller.rb
@@ -0,0 +1,30 @@
+module Api
+ module V1
+
+ class StatementsController < V1Controller
+
+ make_resourceful do
+
+ actions :create
+
+ response_for(:create) do |format|
+ format.html { render :text => 'Statement successfully created', :status => :created }
+ format.xml { render :xml => current_object, :status => :created, :location => api_v1_statement_url(current_object, :format => :xml) }
+ format.js { render :json => current_object, :status => :created, :location => api_v1_statement_url(current_object, :format => :json) }
+ end
+
+ response_for(:create_fails) do |format|
+ format.html { render :text => current_object.errors.full_messages.join('\n'), :status => 400 }
+ format.xml { render :xml => current_object.errors, :status => 400 }
+ format.js { render :json => current_object.errors, :status => 400 }
+ end
+ end
+
+ #-- Make resourceful overrides
+
+ def build_object
+ @current_object ||= current_application.statements.build(object_parameters)
+ end
+ end
+ end
+end
View
6 app/controllers/api/v1/v1_controller.rb
@@ -0,0 +1,6 @@
+module Api
+ module V1
+ class V1Controller < ApiController
+ end
+ end
+end
View
8 app/controllers/application_controller.rb
@@ -0,0 +1,8 @@
+class ApplicationController < ActionController::Base
+
+ include ExceptionNotifiable
+
+ helper :all
+ protect_from_forgery
+
+end
View
30 app/helpers/application_helper.rb
@@ -0,0 +1,30 @@
+module ApplicationHelper
+
+ # Print out all flash messages in a span of the same
+ # class as the message type
+ def flash_messages
+ html = flash.collect do |type, message|
+ content_tag(:div, message, :class => type)
+ end
+ flash.clear # Not sure why we have to manually do this sometimes
+ html
+ end
+
+ # Are there any flash messages to display?
+ def flash_messages?; flash.any?; end
+
+ # Set the page title
+ def page_title(title)
+ content_for :page_title, title
+ end
+
+ # Set the html header title
+ def head_title(title)
+ content_for :head_title, title
+ end
+
+ # Get the authenticity token (useful for an ajax call)
+ def auth_token
+ (protect_against_forgery? ? form_authenticity_token : nil)
+ end
+end
View
16 app/models/application.rb
@@ -0,0 +1,16 @@
+class Application < ActiveRecord::Base
+
+ has_many :statements, :dependent => :delete_all
+
+ validates_presence_of :name, :token
+ validates_uniqueness_of :token
+ validates_uniqueness_of :name, :scope => "account_id"
+
+ before_validation :generate_token
+
+ private
+
+ def generate_token
+ self.token = ActiveSupport::SecureRandom.hex(16) if token.nil?
+ end
+end
View
14 app/models/statement.rb
@@ -0,0 +1,14 @@
+class Statement < ActiveRecord::Base
+
+ belongs_to :application
+
+ validates_presence_of :application, :device_id, :level, :message
+
+ before_validation_on_create :normalize_level
+
+ private
+
+ def normalize_level
+ self.level = level.upcase if level
+ end
+end
View
110 config/boot.rb
@@ -0,0 +1,110 @@
+# Don't change this file!
+# Configure your app in config/environment.rb and config/environments/*.rb
+
+RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
+
+module Rails
+ class << self
+ def boot!
+ unless booted?
+ preinitialize
+ pick_boot.run
+ end
+ end
+
+ def booted?
+ defined? Rails::Initializer
+ end
+
+ def pick_boot
+ (vendor_rails? ? VendorBoot : GemBoot).new
+ end
+
+ def vendor_rails?
+ File.exist?("#{RAILS_ROOT}/vendor/rails")
+ end
+
+ def preinitialize
+ load(preinitializer_path) if File.exist?(preinitializer_path)
+ end
+
+ def preinitializer_path
+ "#{RAILS_ROOT}/config/preinitializer.rb"
+ end
+ end
+
+ class Boot
+ def run
+ load_initializer
+ Rails::Initializer.run(:set_load_path)
+ end
+ end
+
+ class VendorBoot < Boot
+ def load_initializer
+ require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
+ Rails::Initializer.run(:install_gem_spec_stubs)
+ Rails::GemDependency.add_frozen_gem_path
+ end
+ end
+
+ class GemBoot < Boot
+ def load_initializer
+ self.class.load_rubygems
+ load_rails_gem
+ require 'initializer'
+ end
+
+ def load_rails_gem
+ if version = self.class.gem_version
+ gem 'rails', version
+ else
+ gem 'rails'
+ end
+ rescue Gem::LoadError => load_error
+ $stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
+ exit 1
+ end
+
+ class << self
+ def rubygems_version
+ Gem::RubyGemsVersion rescue nil
+ end
+
+ def gem_version
+ if defined? RAILS_GEM_VERSION
+ RAILS_GEM_VERSION
+ elsif ENV.include?('RAILS_GEM_VERSION')
+ ENV['RAILS_GEM_VERSION']
+ else
+ parse_gem_version(read_environment_rb)
+ end
+ end
+
+ def load_rubygems
+ require 'rubygems'
+ min_version = '1.3.1'
+ unless rubygems_version >= min_version
+ $stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
+ exit 1
+ end
+
+ rescue LoadError
+ $stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org)
+ exit 1
+ end
+
+ def parse_gem_version(text)
+ $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
+ end
+
+ private
+ def read_environment_rb
+ File.read("#{RAILS_ROOT}/config/environment.rb")
+ end
+ end
+ end
+end
+
+# All that for this:
+Rails.boot!
View
46 config/environment.rb
@@ -0,0 +1,46 @@
+# Be sure to restart your server when you modify this file
+
+# Specifies gem version of Rails to use when vendor/rails is not present
+RAILS_GEM_VERSION = '2.3.2' unless defined? RAILS_GEM_VERSION
+
+# Bootstrap the Rails environment, frameworks, and default configuration
+require File.join(File.dirname(__FILE__), 'boot')
+
+Rails::Initializer.run do |config|
+
+ config.gem 'mislav-will_paginate', :lib => 'will_paginate', :source => 'http://gems.github.com'
+ config.gem 'yfactorial-utility_scopes', :lib => 'utility_scopes', :source => 'http://gems.github.com/'
+ config.gem 'haml', :version => '2.1.0'
+
+ # Settings in config/environments/* take precedence over those specified here.
+ # Application configuration should go into files in config/initializers
+ # -- all .rb files in that directory are automatically loaded.
+
+ # Add additional load paths for your own custom dirs
+ # config.load_paths += %W( #{RAILS_ROOT}/extras )
+
+ # Specify gems that this application depends on and have them installed with rake gems:install
+ # config.gem "bj"
+ # config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net"
+ # config.gem "sqlite3-ruby", :lib => "sqlite3"
+ # config.gem "aws-s3", :lib => "aws/s3"
+
+ # Only load the plugins named here, in the order given (default is alphabetical).
+ # :all can be used as a placeholder for all plugins not explicitly named
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
+
+ # Skip frameworks you're not going to use. To use Rails without a database,
+ # you must remove the Active Record framework.
+ config.frameworks -= [ :active_resource, :action_mailer ]
+
+ # Activate observers that should always be running
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
+
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
+ # Run "rake -D time" for a list of tasks for finding time zone names.
+ config.time_zone = 'UTC'
+
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')]
+ # config.i18n.default_locale = :de
+end
View
17 config/environments/development.rb
@@ -0,0 +1,17 @@
+# Settings specified here will take precedence over those in config/environment.rb
+
+# In the development environment your application's code is reloaded on
+# every request. This slows down response time but is perfect for development
+# since you don't have to restart the webserver when you make code changes.
+config.cache_classes = false
+
+# Log error messages when you accidentally call methods on nil.
+config.whiny_nils = true
+
+# Show full error reports and disable caching
+config.action_controller.consider_all_requests_local = true
+config.action_view.debug_rjs = true
+config.action_controller.perform_caching = false
+
+# Don't care if the mailer can't send
+config.action_mailer.raise_delivery_errors = false
View
28 config/environments/production.rb
@@ -0,0 +1,28 @@
+# Settings specified here will take precedence over those in config/environment.rb
+
+# The production environment is meant for finished, "live" apps.
+# Code is not reloaded between requests
+config.cache_classes = true
+
+# Full error reports are disabled and caching is turned on
+config.action_controller.consider_all_requests_local = false
+config.action_controller.perform_caching = true
+config.action_view.cache_template_loading = true
+
+# See everything in the log (default is :info)
+# config.log_level = :debug
+
+# Use a different logger for distributed setups
+# config.logger = SyslogLogger.new
+
+# Use a different cache store in production
+# config.cache_store = :mem_cache_store
+
+# Enable serving of images, stylesheets, and javascripts from an asset server
+# config.action_controller.asset_host = "http://assets.example.com"
+
+# Disable delivery errors, bad email addresses will be ignored
+# config.action_mailer.raise_delivery_errors = false
+
+# Enable threaded mode
+# config.threadsafe!
View
28 config/environments/test.rb
@@ -0,0 +1,28 @@
+# Settings specified here will take precedence over those in config/environment.rb
+
+# The test environment is used exclusively to run your application's
+# test suite. You never need to work with it otherwise. Remember that
+# your test database is "scratch space" for the test suite and is wiped
+# and recreated between test runs. Don't rely on the data there!
+config.cache_classes = true
+
+# Log error messages when you accidentally call methods on nil.
+config.whiny_nils = true
+
+# Show full error reports and disable caching
+config.action_controller.consider_all_requests_local = true
+config.action_controller.perform_caching = false
+config.action_view.cache_template_loading = true
+
+# Disable request forgery protection in test environment
+config.action_controller.allow_forgery_protection = false
+
+# Tell Action Mailer not to deliver emails to the real world.
+# The :test delivery method accumulates sent emails in the
+# ActionMailer::Base.deliveries array.
+config.action_mailer.delivery_method = :test
+
+# Use SQL instead of Active Record's schema dumper when creating the test database.
+# This is necessary if your schema can't be completely dumped by the schema dumper,
+# like if you have constraints or database-specific column types
+# config.active_record.schema_format = :sql
View
7 config/initializers/backtrace_silencers.rb
@@ -0,0 +1,7 @@
+# Be sure to restart your server when you modify this file.
+
+# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
+# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
+
+# You can also remove all the silencers if you're trying do debug a problem that might steem from framework code.
+# Rails.backtrace_cleaner.remove_silencers!
View
3 config/initializers/exception_notifications.rb
@@ -0,0 +1,3 @@
+ExceptionNotifier.exception_recipients = %w(ryan.daigle+remotelogger@gmail.com)
+ExceptionNotifier.sender_address = %("RemoteLogger Error" <errors@remotelogger.com>)
+ExceptionNotifier.email_prefix = ENV['RAILS_ENV'] ? "[#{ENV['RAILS_ENV'].upcase}]" : ''
View
10 config/initializers/inflections.rb
@@ -0,0 +1,10 @@
+# Be sure to restart your server when you modify this file.
+
+# Add new inflection rules using the following format
+# (all these examples are active by default):
+# ActiveSupport::Inflector.inflections do |inflect|
+# inflect.plural /^(ox)$/i, '\1en'
+# inflect.singular /^(ox)en/i, '\1'
+# inflect.irregular 'person', 'people'
+# inflect.uncountable %w( fish sheep )
+# end
View
5 config/initializers/mime_types.rb
@@ -0,0 +1,5 @@
+# Be sure to restart your server when you modify this file.
+
+# Add new mime types for use in respond_to blocks:
+# Mime::Type.register "text/richtext", :rtf
+# Mime::Type.register_alias "text/html", :iphone
View
19 config/initializers/new_rails_defaults.rb
@@ -0,0 +1,19 @@
+# Be sure to restart your server when you modify this file.
+
+# These settings change the behavior of Rails 2 apps and will be defaults
+# for Rails 3. You can remove this initializer when Rails 3 is released.
+
+if defined?(ActiveRecord)
+ # Include Active Record class name as root for JSON serialized output.
+ ActiveRecord::Base.include_root_in_json = true
+
+ # Store the full class name (including module namespace) in STI type column.
+ ActiveRecord::Base.store_full_sti_class = true
+end
+
+# Use ISO 8601 format for JSON serialized times and dates.
+ActiveSupport.use_standard_json_time_format = true
+
+# Don't escape HTML entities in JSON, leave that for the #json_escape helper.
+# if you're including raw json in an HTML page.
+ActiveSupport.escape_html_entities_in_json = false
View
15 config/initializers/session_store.rb
@@ -0,0 +1,15 @@
+# Be sure to restart your server when you modify this file.
+
+# Your secret key for verifying cookie session data integrity.
+# If you change this key, all old sessions will become invalid!
+# Make sure the secret is at least 30 characters and all random,
+# no regular words or you'll be exposed to dictionary attacks.
+ActionController::Base.session = {
+ :key => '_remotelogger-server_session',
+ :secret => 'b1216823238e1883d49fa246d05bfc9d27c8606ce322c03f6cbd325f7a4c4829b9392c2f935ad10d99fc96eafbda4b7d32258665011e5af8c8eaeef27ed5f457'
+}
+
+# Use the database for sessions instead of the cookie-based default,
+# which shouldn't be used to store highly confidential information
+# (create the session table with "rake db:sessions:create")
+# ActionController::Base.session_store = :active_record_store
View
1 config/initializers/will_paginate.rb
@@ -0,0 +1 @@
+ActiveRecord::Base.class_eval { def self.per_page; 10; end }
View
5 config/locales/en.yml
@@ -0,0 +1,5 @@
+# Sample localization file for English. Add more files in this directory for other locales.
+# See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
+
+en:
+ hello: "Hello world"
View
145 config/newrelic.yml
@@ -0,0 +1,145 @@
+#
+# This file configures the NewRelic RPM Agent, NewRelic RPM monitors Rails
+# applications with deep visibility and low overhead. For more information,
+# visit www.newrelic.com.
+#
+# This configuration file is custom generated for Y|Factorial, LLC
+#
+# here are the settings that are common to all environments
+common: &default_settings
+ # ============================== LICENSE KEY ===============================
+ # You must specify the licence key associated with your New Relic account.
+ # This key binds your Agent's data to your account in the New Relic RPM service.
+ license_key: 'fecac1a2d4c32983cf851c90b77d867849928135'
+
+ # Agent Enabled
+ # Use this setting to force the agent to run or not run.
+ # Default is 'auto' which means the agent will install and run only if a
+ # valid dispatcher such as Mongrel is running. This prevents it from running
+ # with Rake or the console. Set to false to completely turn the agent off
+ # regardless of the other settings. Valid values are true, false and auto.
+ # agent_enabled: auto
+
+ # Application Name
+ # Set this to be the name of your application as you'd like it show up in RPM.
+ # RPM will then auto-map instances of your application into a RPM "application"
+ # on your home dashboard page. This setting does not prevent you from manually
+ # defining applications.
+ app_name: RemoteLogger
+
+ # the 'enabled' setting is used to turn on the NewRelic Agent. When false,
+ # your application is not instrumented and the Agent does not start up or
+ # collect any data; it is a complete shut-off.
+ #
+ # when turned on, the agent collects performance data by inserting lightweight
+ # tracers on key methods inside the rails framework and asynchronously aggregating
+ # and reporting this performance data to the NewRelic RPM service at NewRelic.com.
+ # below.
+ enabled: true
+
+ # The newrelic agent generates its own log file to keep its logging information
+ # separate from that of your application. Specify its log level here.
+ log_level: info
+
+ # The newrelic agent communicates with the RPM service via http by default.
+ # If you want to communicate via https to increase security, then turn on
+ # SSL by setting this value to true. Note, this will result in increased
+ # CPU overhead to perform the encryption involved in SSL communication, but this
+ # work is done asynchronously to the threads that process your application code, so
+ # it should not impact response times.
+ ssl: false
+
+
+ # Proxy settings for connecting to the RPM server.
+ #
+ # If a proxy is used, the host setting is required. Other settings are optional. Default
+ # port is 8080.
+ #
+ # proxy_host: hostname
+ # proxy_port: 8080
+ # proxy_user:
+ # proxy_pass:
+
+
+ # Tells transaction tracer and error collector (when enabled) whether or not to capture HTTP params.
+ # When true, the RoR filter_parameter_logging mechanism is used so that sensitive parameters are not recorded
+ capture_params: true
+
+
+ # Transaction tracer captures deep information about slow
+ # transactions and sends this to the RPM service once a minute. Included in the
+ # transaction is the exact call sequence of the transactions including any SQL statements
+ # issued.
+ transaction_tracer:
+
+ # Transaction tracer is enabled by default. Set this to false to turn it off. This feature
+ # is only available at the Silver and above product levels.
+ enabled: true
+
+
+ # When transaction tracer is on, SQL statements can optionally be recorded. The recorder
+ # has three modes, "off" which sends no SQL, "raw" which sends the SQL statement in its
+ # original form, and "obfuscated", which strips out numeric and string literals
+ record_sql: raw
+
+ # Threshold in seconds for when to collect stack trace for a SQL call. In other words,
+ # when SQL statements exceed this threshold, then capture and send to RPM the current
+ # stack trace. This is helpful for pinpointing where long SQL calls originate from
+ stack_trace_threshold: 0.500
+
+ # Error collector captures information about uncaught exceptions and sends them to RPM for
+ # viewing
+ error_collector:
+
+ # Error collector is enabled by default. Set this to false to turn it off. This feature
+ # is only available at the Silver and above product levels
+ enabled: true
+
+ # Tells error collector whether or not to capture a source snippet around the place of the
+ # error when errors are View related.
+ capture_source: true
+
+ # To stop specific errors from reporting to RPM, set this property to comma separated
+ # values
+ #
+ #ignore_errors: ActionController::RoutingError, ...
+
+
+# override default settings based on your application's environment
+
+# NOTE if your application has other named environments, you should
+# provide newrelic conifguration settings for these enviromnents here.
+
+development:
+ <<: *default_settings
+ # turn off communication to RPM service in development mode.
+ # NOTE: for initial evaluation purposes, you may want to temporarily turn
+ # the agent on in development mode.
+ enabled: false
+
+ # When running in Developer Mode, the New Relic Agent will present
+ # performance information on the last 100 transactions you have
+ # executed since starting the mongrel. to view this data, go to
+ # http://localhost:3000/newrelic
+ developer: true
+
+test:
+ <<: *default_settings
+ # it almost never makes sense to turn on the agent when running unit, functional or
+ # integration tests or the like.
+ enabled: false
+
+# Turn on the agent in production for 24x7 monitoring. NewRelic testing shows
+# an average performance impact of < 5 ms per transaction, you you can leave this on
+# all the time without incurring any user-visible performance degredation.
+production:
+ <<: *default_settings
+ enabled: true
+
+# many applications have a staging environment which behaves identically to production.
+# Support for that environment is provided here. By default, the staging environment has
+# the agent turned on.
+staging:
+ <<: *default_settings
+ enabled: true
+ app_name: RemoteLogger (Staging)
View
9 config/routes.rb
@@ -0,0 +1,9 @@
+ActionController::Routing::Routes.draw do |map|
+
+ # Initial version of API
+ map.namespace :api do |api|
+ api.namespace :v1 do |v1|
+ v1.resources :statements, :only => [:show, :create]
+ end
+ end
+end
View
27 db/migrate/20090401132240_initial_release.rb
@@ -0,0 +1,27 @@
+class InitialRelease < ActiveRecord::Migration
+
+ def self.up
+
+ create_table :applications do |t|
+ t.belongs_to :account
+ t.string :name, :token, :null => false
+ t.timestamps
+ end
+ add_index :applications, :token
+ add_index :applications, :account_id
+
+ create_table :statements do |t|
+ t.belongs_to :application, :null => false
+ t.string :device_id, :level, :null => false
+ t.text :message, :null => false
+ t.timestamp :logged_at
+ t.timestamps
+ end
+ add_index :statements, :application_id
+ add_index :statements, :level
+ add_index :statements, [:logged_at, :created_at]
+ end
+
+ def self.down
+ end
+end
View
2 doc/README_FOR_APP
@@ -0,0 +1,2 @@
+Use this README file to introduce your application and point to useful places in the API for learning more.
+Run "rake doc:app" to generate API documentation for your models, controllers, helpers, and libraries.
View
4 lib/tasks/db.rake
@@ -0,0 +1,4 @@
+namespace :db do
+ desc "Drop the dbs, and does a full migrate to bring it back up"
+ task :revert => ['db:drop', 'db:create', 'db:migrate']
+end
View
165 lib/tasks/rspec.rake
@@ -0,0 +1,165 @@
+gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9
+
+# Don't load rspec if running "rake gems:*"
+unless ARGV.any? {|a| a =~ /^gems/}
+
+begin
+ require 'spec/rake/spectask'
+rescue MissingSourceFile
+ module Spec
+ module Rake
+ class SpecTask
+ def initialize(name)
+ task name do
+ # if rspec-rails is a configured gem, this will output helpful material and exit ...
+ require File.expand_path(File.dirname(__FILE__) + "/../../config/environment")
+
+ # ... otherwise, do this:
+ raise <<-MSG
+
+#{"*" * 80}
+* You are trying to run an rspec rake task defined in
+* #{__FILE__},
+* but rspec can not be found in vendor/gems, vendor/plugins or system gems.
+#{"*" * 80}
+MSG
+ end
+ end
+ end
+ end
+ end
+end
+
+Rake.application.instance_variable_get('@tasks').delete('default')
+
+spec_prereq = File.exist?(File.join(RAILS_ROOT, 'config', 'database.yml')) ? "db:test:prepare" : :noop
+task :noop do
+end
+
+task :default => :spec
+task :stats => "spec:statsetup"
+
+desc "Run all specs in spec directory (excluding plugin specs)"
+Spec::Rake::SpecTask.new(:spec => spec_prereq) do |t|
+ t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
+ t.spec_files = FileList['spec/**/*/*_spec.rb']
+end
+
+namespace :spec do
+ desc "Run all specs in spec directory with RCov (excluding plugin specs)"
+ Spec::Rake::SpecTask.new(:rcov) do |t|
+ t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
+ t.spec_files = FileList['spec/**/*/*_spec.rb']
+ t.rcov = true
+ t.rcov_opts = lambda do
+ IO.readlines("#{RAILS_ROOT}/spec/rcov.opts").map {|l| l.chomp.split " "}.flatten
+ end
+ end
+
+ desc "Print Specdoc for all specs (excluding plugin specs)"
+ Spec::Rake::SpecTask.new(:doc) do |t|
+ t.spec_opts = ["--format", "specdoc", "--dry-run"]
+ t.spec_files = FileList['spec/**/*/*_spec.rb']
+ end
+
+ desc "Print Specdoc for all plugin examples"
+ Spec::Rake::SpecTask.new(:plugin_doc) do |t|
+ t.spec_opts = ["--format", "specdoc", "--dry-run"]
+ t.spec_files = FileList['vendor/plugins/**/spec/**/*/*_spec.rb'].exclude('vendor/plugins/rspec/*')
+ end
+
+ [:models, :controllers, :views, :helpers, :lib].each do |sub|
+ desc "Run the code examples in spec/#{sub}"
+ Spec::Rake::SpecTask.new(sub => spec_prereq) do |t|
+ t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
+ t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
+ end
+ end
+
+ desc "Run the code examples in vendor/plugins (except RSpec's own)"
+ Spec::Rake::SpecTask.new(:plugins => spec_prereq) do |t|
+ t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
+ t.spec_files = FileList['vendor/plugins/**/spec/**/*/*_spec.rb'].exclude('vendor/plugins/rspec/*').exclude("vendor/plugins/rspec-rails/*")
+ end
+
+ namespace :plugins do
+ desc "Runs the examples for rspec_on_rails"
+ Spec::Rake::SpecTask.new(:rspec_on_rails) do |t|
+ t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
+ t.spec_files = FileList['vendor/plugins/rspec-rails/spec/**/*/*_spec.rb']
+ end
+ end
+
+ # Setup specs for stats
+ task :statsetup do
+ require 'code_statistics'
+ ::STATS_DIRECTORIES << %w(Model\ specs spec/models) if File.exist?('spec/models')
+ ::STATS_DIRECTORIES << %w(View\ specs spec/views) if File.exist?('spec/views')
+ ::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers) if File.exist?('spec/controllers')
+ ::STATS_DIRECTORIES << %w(Helper\ specs spec/helpers) if File.exist?('spec/helpers')
+ ::STATS_DIRECTORIES << %w(Library\ specs spec/lib) if File.exist?('spec/lib')
+ ::STATS_DIRECTORIES << %w(Routing\ specs spec/lib) if File.exist?('spec/routing')
+ ::CodeStatistics::TEST_TYPES << "Model specs" if File.exist?('spec/models')
+ ::CodeStatistics::TEST_TYPES << "View specs" if File.exist?('spec/views')
+ ::CodeStatistics::TEST_TYPES << "Controller specs" if File.exist?('spec/controllers')
+ ::CodeStatistics::TEST_TYPES << "Helper specs" if File.exist?('spec/helpers')
+ ::CodeStatistics::TEST_TYPES << "Library specs" if File.exist?('spec/lib')
+ ::CodeStatistics::TEST_TYPES << "Routing specs" if File.exist?('spec/routing')
+ end
+
+ namespace :db do
+ namespace :fixtures do
+ desc "Load fixtures (from spec/fixtures) into the current environment's database. Load specific fixtures using FIXTURES=x,y. Load from subdirectory in test/fixtures using FIXTURES_DIR=z."
+ task :load => :environment do
+ ActiveRecord::Base.establish_connection(Rails.env)
+ base_dir = File.join(Rails.root, 'spec', 'fixtures')
+ fixtures_dir = ENV['FIXTURES_DIR'] ? File.join(base_dir, ENV['FIXTURES_DIR']) : base_dir
+
+ require 'active_record/fixtures'
+ (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/).map {|f| File.join(fixtures_dir, f) } : Dir.glob(File.join(fixtures_dir, '*.{yml,csv}'))).each do |fixture_file|
+ Fixtures.create_fixtures(File.dirname(fixture_file), File.basename(fixture_file, '.*'))
+ end
+ end
+ end
+ end
+
+ namespace :server do
+ daemonized_server_pid = File.expand_path("#{RAILS_ROOT}/tmp/pids/spec_server.pid")
+
+ desc "start spec_server."
+ task :start do
+ if File.exist?(daemonized_server_pid)
+ $stderr.puts "spec_server is already running."
+ else
+ $stderr.puts %Q{Starting up spec_server ...}
+ FileUtils.mkdir_p('tmp/pids') unless test ?d, 'tmp/pids'
+ system("ruby", "script/spec_server", "--daemon", "--pid", daemonized_server_pid)
+ end
+ end
+
+ desc "stop spec_server."
+ task :stop do
+ unless File.exist?(daemonized_server_pid)
+ $stderr.puts "No server running."
+ else
+ $stderr.puts "Shutting down spec_server ..."
+ system("kill", "-s", "TERM", File.read(daemonized_server_pid).strip) &&
+ File.delete(daemonized_server_pid)
+ end
+ end
+
+ desc "restart spec_server."
+ task :restart => [:stop, :start]
+
+ desc "check if spec server is running"
+ task :status do
+ if File.exist?(daemonized_server_pid)
+ $stderr.puts %Q{spec_server is running (PID: #{File.read(daemonized_server_pid).gsub("\n","")})}
+ else
+ $stderr.puts "No server running."
+ end
+ end
+ end
+end
+
+end
View
30 public/404.html
@@ -0,0 +1,30 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+
+<head>
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
+ <title>The page you were looking for doesn't exist (404)</title>
+ <style type="text/css">
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
+ div.dialog {
+ width: 25em;
+ padding: 0 4em;
+ margin: 4em auto 0 auto;
+ border: 1px solid #ccc;
+ border-right-color: #999;
+ border-bottom-color: #999;
+ }
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
+ </style>
+</head>
+
+<body>
+ <!-- This file lives in public/404.html -->
+ <div class="dialog">
+ <h1>The page you were looking for doesn't exist.</h1>
+ <p>You may have mistyped the address or the page may have moved.</p>
+ </div>
+</body>
+</html>
View
30 public/422.html
@@ -0,0 +1,30 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+
+<head>
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
+ <title>The change you wanted was rejected (422)</title>
+ <style type="text/css">
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
+ div.dialog {
+ width: 25em;
+ padding: 0 4em;
+ margin: 4em auto 0 auto;
+ border: 1px solid #ccc;
+ border-right-color: #999;
+ border-bottom-color: #999;
+ }
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
+ </style>
+</head>
+
+<body>
+ <!-- This file lives in public/422.html -->
+ <div class="dialog">
+ <h1>The change you wanted was rejected.</h1>
+ <p>Maybe you tried to change something you didn't have access to.</p>
+ </div>
+</body>
+</html>
View
30 public/500.html
@@ -0,0 +1,30 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+
+<head>
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
+ <title>We're sorry, but something went wrong (500)</title>
+ <style type="text/css">
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
+ div.dialog {
+ width: 25em;
+ padding: 0 4em;
+ margin: 4em auto 0 auto;
+ border: 1px solid #ccc;
+ border-right-color: #999;
+ border-bottom-color: #999;
+ }
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
+ </style>
+</head>
+
+<body>
+ <!-- This file lives in public/500.html -->
+ <div class="dialog">
+ <h1>We're sorry, but something went wrong.</h1>
+ <p>We've been notified about this issue and we'll take a look at it shortly.</p>
+ </div>
+</body>
+</html>
View
0 public/favicon.ico
No changes.
View
BIN public/images/rails.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
275 public/index.html
@@ -0,0 +1,275 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html>
+ <head>
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
+ <title>Ruby on Rails: Welcome aboard</title>
+ <style type="text/css" media="screen">
+ body {
+ margin: 0;
+ margin-bottom: 25px;
+ padding: 0;
+ background-color: #f0f0f0;
+ font-family: "Lucida Grande", "Bitstream Vera Sans", "Verdana";
+ font-size: 13px;
+ color: #333;
+ }
+
+ h1 {
+ font-size: 28px;
+ color: #000;
+ }
+
+ a {color: #03c}
+ a:hover {
+ background-color: #03c;
+ color: white;
+ text-decoration: none;
+ }
+
+
+ #page {
+ background-color: #f0f0f0;
+ width: 750px;
+ margin: 0;
+ margin-left: auto;
+ margin-right: auto;
+ }
+
+ #content {
+ float: left;
+ background-color: white;
+ border: 3px solid #aaa;
+ border-top: none;
+ padding: 25px;
+ width: 500px;
+ }
+
+ #sidebar {
+ float: right;
+ width: 175px;
+ }
+
+ #footer {
+ clear: both;
+ }
+
+
+ #header, #about, #getting-started {
+ padding-left: 75px;
+ padding-right: 30px;
+ }
+
+
+ #header {
+ background-image: url("images/rails.png");
+ background-repeat: no-repeat;
+ background-position: top left;
+ height: 64px;
+ }
+ #header h1, #header h2 {margin: 0}
+ #header h2 {
+ color: #888;
+ font-weight: normal;
+ font-size: 16px;
+ }
+
+
+ #about h3 {
+ margin: 0;
+ margin-bottom: 10px;
+ font-size: 14px;
+ }
+
+ #about-content {
+ background-color: #ffd;
+ border: 1px solid #fc0;
+ margin-left: -11px;
+ }
+ #about-content table {
+ margin-top: 10px;
+ margin-bottom: 10px;
+ font-size: 11px;
+ border-collapse: collapse;
+ }
+ #about-content td {
+ padding: 10px;
+ padding-top: 3px;
+ padding-bottom: 3px;
+ }
+ #about-content td.name {color: #555}
+ #about-content td.value {color: #000}
+
+ #about-content.failure {
+ background-color: #fcc;
+ border: 1px solid #f00;
+ }
+ #about-content.failure p {
+ margin: 0;
+ padding: 10px;
+ }
+
+
+ #getting-started {
+ border-top: 1px solid #ccc;
+ margin-top: 25px;
+ padding-top: 15px;
+ }
+ #getting-started h1 {
+ margin: 0;
+ font-size: 20px;
+ }
+ #getting-started h2 {
+ margin: 0;
+ font-size: 14px;
+ font-weight: normal;
+ color: #333;
+ margin-bottom: 25px;
+ }
+ #getting-started ol {
+ margin-left: 0;
+ padding-left: 0;
+ }
+ #getting-started li {
+ font-size: 18px;
+ color: #888;
+ margin-bottom: 25px;
+ }
+ #getting-started li h2 {
+ margin: 0;
+ font-weight: normal;
+ font-size: 18px;
+ color: #333;
+ }
+ #getting-started li p {
+ color: #555;
+ font-size: 13px;
+ }
+
+
+ #search {
+ margin: 0;
+ padding-top: 10px;
+ padding-bottom: 10px;
+ font-size: 11px;
+ }
+ #search input {
+ font-size: 11px;
+ margin: 2px;
+ }
+ #search-text {width: 170px}
+
+
+ #sidebar ul {
+ margin-left: 0;
+ padding-left: 0;
+ }
+ #sidebar ul h3 {
+ margin-top: 25px;
+ font-size: 16px;
+ padding-bottom: 10px;
+ border-bottom: 1px solid #ccc;
+ }
+ #sidebar li {
+ list-style-type: none;
+ }
+ #sidebar ul.links li {
+ margin-bottom: 5px;
+ }
+
+ </style>
+ <script type="text/javascript" src="javascripts/prototype.js"></script>
+ <script type="text/javascript" src="javascripts/effects.js"></script>
+ <script type="text/javascript">
+ function about() {
+ if (Element.empty('about-content')) {
+ new Ajax.Updater('about-content', 'rails/info/properties', {
+ method: 'get',
+ onFailure: function() {Element.classNames('about-content').add('failure')},
+ onComplete: function() {new Effect.BlindDown('about-content', {duration: 0.25})}
+ });
+ } else {
+ new Effect[Element.visible('about-content') ?
+ 'BlindUp' : 'BlindDown']('about-content', {duration: 0.25});
+ }
+ }
+
+ window.onload = function() {
+ $('search-text').value = '';
+ $('search').onsubmit = function() {
+ $('search-text').value = 'site:rubyonrails.org ' + $F('search-text');
+ }
+ }
+ </script>
+ </head>
+ <body>
+ <div id="page">
+ <div id="sidebar">
+ <ul id="sidebar-items">
+ <li>
+ <form id="search" action="http://www.google.com/search" method="get">
+ <input type="hidden" name="hl" value="en" />
+ <input type="text" id="search-text" name="q" value="site:rubyonrails.org " />
+ <input type="submit" value="Search" /> the Rails site
+ </form>
+ </li>
+
+ <li>
+ <h3>Join the community</h3>
+ <ul class="links">
+ <li><a href="http://www.rubyonrails.org/">Ruby on Rails</a></li>
+ <li><a href="http://weblog.rubyonrails.org/">Official weblog</a></li>
+ <li><a href="http://wiki.rubyonrails.org/">Wiki</a></li>
+ </ul>
+ </li>
+
+ <li>
+ <h3>Browse the documentation</h3>
+ <ul class="links">
+ <li><a href="http://api.rubyonrails.org/">Rails API</a></li>
+ <li><a href="http://stdlib.rubyonrails.org/">Ruby standard library</a></li>
+ <li><a href="http://corelib.rubyonrails.org/">Ruby core</a></li>
+ <li><a href="http://guides.rubyonrails.org/">Rails Guides</a></li>
+ </ul>
+ </li>
+ </ul>
+ </div>
+
+ <div id="content">
+ <div id="header">
+ <h1>Welcome aboard</h1>
+ <h2>You&rsquo;re riding Ruby on Rails!</h2>
+ </div>
+
+ <div id="about">
+ <h3><a href="rails/info/properties" onclick="about(); return false">About your application&rsquo;s environment</a></h3>
+ <div id="about-content" style="display: none"></div>
+ </div>
+
+ <div id="getting-started">
+ <h1>Getting started</h1>
+ <h2>Here&rsquo;s how to get rolling:</h2>
+
+ <ol>
+ <li>
+ <h2>Use <tt>script/generate</tt> to create your models and controllers</h2>
+ <p>To see all available options, run it without parameters.</p>
+ </li>
+
+ <li>
+ <h2>Set up a default route and remove or rename this file</h2>
+ <p>Routes are set up in config/routes.rb.</p>
+ </li>
+
+ <li>
+ <h2>Create your database</h2>
+ <p>Run <tt>rake db:migrate</tt> to create your database. If you're not using SQLite (the default), edit <tt>config/database.yml</tt> with your username and password.</p>
+ </li>
+ </ol>
+ </div>
+ </div>
+
+ <div id="footer">&nbsp;</div>
+ </div>
+ </body>
+</html>
View
2 public/javascripts/application.js
@@ -0,0 +1,2 @@
+// Place your application-specific JavaScript functions and classes here
+// This file is automatically included by javascript_include_tag :defaults
View
963 public/javascripts/controls.js
@@ -0,0 +1,963 @@
+// Copyright (c) 2005-2008 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
+// (c) 2005-2008 Ivan Krstic (http://blogs.law.harvard.edu/ivan)
+// (c) 2005-2008 Jon Tirsen (http://www.tirsen.com)
+// Contributors:
+// Richard Livsey
+// Rahul Bhargava
+// Rob Wills
+//
+// script.aculo.us is freely distributable under the terms of an MIT-style license.
+// For details, see the script.aculo.us web site: http://script.aculo.us/
+
+// Autocompleter.Base handles all the autocompletion functionality
+// that's independent of the data source for autocompletion. This
+// includes drawing the autocompletion menu, observing keyboard
+// and mouse events, and similar.
+//
+// Specific autocompleters need to provide, at the very least,
+// a getUpdatedChoices function that will be invoked every time
+// the text inside the monitored textbox changes. This method
+// should get the text for which to provide autocompletion by
+// invoking this.getToken(), NOT by directly accessing
+// this.element.value. This is to allow incremental tokenized
+// autocompletion. Specific auto-completion logic (AJAX, etc)
+// belongs in getUpdatedChoices.
+//
+// Tokenized incremental autocompletion is enabled automatically
+// when an autocompleter is instantiated with the 'tokens' option
+// in the options parameter, e.g.:
+// new Ajax.Autocompleter('id','upd', '/url/', { tokens: ',' });
+// will incrementally autocomplete with a comma as the token.
+// Additionally, ',' in the above example can be replaced with
+// a token array, e.g. { tokens: [',', '\n'] } which
+// enables autocompletion on multiple tokens. This is most
+// useful when one of the tokens is \n (a newline), as it
+// allows smart autocompletion after linebreaks.
+
+if(typeof Effect == 'undefined')
+ throw("controls.js requires including script.aculo.us' effects.js library");
+
+var Autocompleter = { };
+Autocompleter.Base = Class.create({
+ baseInitialize: function(element, update, options) {
+ element = $(element);
+ this.element = element;
+ this.update = $(update);
+ this.hasFocus = false;
+ this.changed = false;
+ this.active = false;
+ this.index = 0;
+ this.entryCount = 0;
+ this.oldElementValue = this.element.value;
+
+ if(this.setOptions)
+ this.setOptions(options);
+ else
+ this.options = options || { };
+
+ this.options.paramName = this.options.paramName || this.element.name;
+ this.options.tokens = this.options.tokens || [];
+ this.options.frequency = this.options.frequency || 0.4;
+ this.options.minChars = this.options.minChars || 1;
+ this.options.onShow = this.options.onShow ||
+ function(element, update){
+ if(!update.style.position || update.style.position=='absolute') {
+ update.style.position = 'absolute';
+ Position.clone(element, update, {
+ setHeight: false,
+ offsetTop: element.offsetHeight
+ });
+ }
+ Effect.Appear(update,{duration:0.15});
+ };
+ this.options.onHide = this.options.onHide ||
+ function(element, update){ new Effect.Fade(update,{duration:0.15}) };
+
+ if(typeof(this.options.tokens) == 'string')
+ this.options.tokens = new Array(this.options.tokens);
+ // Force carriage returns as token delimiters anyway
+ if (!this.options.tokens.include('\n'))
+ this.options.tokens.push('\n');
+
+ this.observer = null;
+
+ this.element.setAttribute('autocomplete','off');
+
+ Element.hide(this.update);
+
+ Event.observe(this.element, 'blur', this.onBlur.bindAsEventListener(this));
+ Event.observe(this.element, 'keydown', this.onKeyPress.bindAsEventListener(this));
+ },
+
+ show: function() {
+ if(Element.getStyle(this.update, 'display')=='none') this.options.onShow(this.element, this.update);
+ if(!this.iefix &&
+ (Prototype.Browser.IE) &&
+ (Element.getStyle(this.update, 'position')=='absolute')) {
+ new Insertion.After(this.update,
+ '<iframe id="' + this.update.id + '_iefix" '+
+ 'style="display:none;position:absolute;filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);" ' +
+ 'src="javascript:false;" frameborder="0" scrolling="no"></iframe>');
+ this.iefix = $(this.update.id+'_iefix');
+ }
+ if(this.iefix) setTimeout(this.fixIEOverlapping.bind(this), 50);
+ },
+
+ fixIEOverlapping: function() {
+ Position.clone(this.update, this.iefix, {setTop:(!this.update.style.height)});
+ this.iefix.style.zIndex = 1;
+ this.update.style.zIndex = 2;
+ Element.show(this.iefix);
+ },
+
+ hide: function() {
+ this.stopIndicator();
+ if(Element.getStyle(this.update, 'display')!='none') this.options.onHide(this.element, this.update);
+ if(this.iefix) Element.hide(this.iefix);
+ },
+
+ startIndicator: function() {
+ if(this.options.indicator) Element.show(this.options.indicator);
+ },
+
+ stopIndicator: function() {
+ if(this.options.indicator) Element.hide(this.options.indicator);
+ },
+
+ onKeyPress: function(event) {
+ if(this.active)
+ switch(event.keyCode) {
+ case Event.KEY_TAB:
+ case Event.KEY_RETURN:
+ this.selectEntry();
+ Event.stop(event);
+ case Event.KEY_ESC:
+ this.hide();
+ this.active = false;
+ Event.stop(event);
+ return;
+ case Event.KEY_LEFT:
+ case Event.KEY_RIGHT:
+ return;
+ case Event.KEY_UP:
+ this.markPrevious();
+ this.render();
+ Event.stop(event);
+ return;
+ case Event.KEY_DOWN:
+ this.markNext();
+ this.render();
+ Event.stop(event);
+ return;
+ }
+ else
+ if(event.keyCode==Event.KEY_TAB || event.keyCode==Event.KEY_RETURN ||
+ (Prototype.Browser.WebKit > 0 && event.keyCode == 0)) return;
+
+ this.changed = true;
+ this.hasFocus = true;
+
+ if(this.observer) clearTimeout(this.observer);
+ this.observer =
+ setTimeout(this.onObserverEvent.bind(this), this.options.frequency*1000);
+ },
+
+ activate: function() {
+ this.changed = false;
+ this.hasFocus = true;
+ this.getUpdatedChoices();
+ },
+
+ onHover: function(event) {
+ var element = Event.findElement(event, 'LI');
+ if(this.index != element.autocompleteIndex)
+ {
+ this.index = element.autocompleteIndex;
+ this.render();
+ }
+ Event.stop(event);
+ },
+
+ onClick: function(event) {
+ var element = Event.findElement(event, 'LI');
+ this.index = element.autocompleteIndex;
+ this.selectEntry();
+ this.hide();
+ },
+
+ onBlur: function(event) {
+ // needed to make click events working
+ setTimeout(this.hide.bind(this), 250);
+ this.hasFocus = false;
+ this.active = false;
+ },
+
+ render: function() {
+ if(this.entryCount > 0) {
+ for (var i = 0; i < this.entryCount; i++)
+ this.index==i ?
+ Element.addClassName(this.getEntry(i),"selected") :
+ Element.removeClassName(this.getEntry(i),"selected");
+ if(this.hasFocus) {
+ this.show();
+ this.active = true;
+ }
+ } else {
+ this.active = false;
+ this.hide();
+ }
+ },
+
+ markPrevious: function() {
+ if(this.index > 0) this.index--;
+ else this.index = this.entryCount-1;
+ this.getEntry(this.index).scrollIntoView(true);
+ },
+
+ markNext: function() {
+ if(this.index < this.entryCount-1) this.index++;
+ else this.index = 0;
+ this.getEntry(this.index).scrollIntoView(false);
+ },
+
+ getEntry: function(index) {
+ return this.update.firstChild.childNodes[index];
+ },
+
+ getCurrentEntry: function() {
+ return this.getEntry(this.index);
+ },
+
+ selectEntry: function() {
+ this.active = false;
+ this.updateElement(this.getCurrentEntry());
+ },
+
+ updateElement: function(selectedElement) {
+ if (this.options.updateElement) {
+ this.options.updateElement(selectedElement);
+ return;
+ }
+ var value = '';
+ if (this.options.select) {
+ var nodes = $(selectedElement).select('.' + this.options.select) || [];
+ if(nodes.length>0) value = Element.collectTextNodes(nodes[0], this.options.select);
+ } else
+ value = Element.collectTextNodesIgnoreClass(selectedElement, 'informal');
+
+ var bounds = this.getTokenBounds();
+ if (bounds[0] != -1) {
+ var newValue = this.element.value.substr(0, bounds[0]);
+ var whitespace = this.element.value.substr(bounds[0]).match(/^\s+/);
+ if (whitespace)
+ newValue += whitespace[0];
+ this.element.value = newValue + value + this.element.value.substr(bounds[1]);
+ } else {
+ this.element.value = value;
+ }
+ this.oldElementValue = this.element.value;
+ this.element.focus();
+
+ if (this.options.afterUpdateElement)
+ this.options.afterUpdateElement(this.element, selectedElement);
+ },
+
+ updateChoices: function(choices) {
+ if(!this.changed && this.hasFocus) {
+ this.update.innerHTML = choices;
+ Element.cleanWhitespace(this.update);
+ Element.cleanWhitespace(this.update.down());
+
+ if(this.update.firstChild && this.update.down().childNodes) {
+ this.entryCount =
+ this.update.down().childNodes.length;
+ for (var i = 0; i < this.entryCount; i++) {
+ var entry = this.getEntry(i);
+ entry.autocompleteIndex = i;
+ this.addObservers(entry);
+ }
+ } else {
+ this.entryCount = 0;
+ }
+
+ this.stopIndicator();
+ this.index = 0;
+
+ if(this.entryCount==1 && this.options.autoSelect) {
+ this.selectEntry();
+ this.hide();
+ } else {
+ this.render();
+ }
+ }