lib/nitro/helper/javascript.rb in nitro-0.31.0 vs lib/nitro/helper/javascript.rb in nitro-0.40.0
- old
+ new
@@ -1,13 +1,33 @@
+#--
+# WARNING: most of the code here is deprecated and will be
+# replaced. Use with caution.
+#++
+
require 'facet/inflect'
module Nitro
+# Javascript code manager.
+#--
+# TODO: Add support for synthesizing compound Javascript files from
+# multiple smaller files.
+#++
+
module Javascript
+
# The javascript files to auto include.
setting :required_files, :default => [], :doc => 'The javascript files to auto include'
+
+ # The root directory where javascript files reside.
+
+ setting :root_dir, :default => 'public/js', :doc => 'The root directory where javascript files reside'
+
+ def self.require path
+ end
+
end
# Javascript utilities.
module JavascriptUtils
@@ -15,10 +35,11 @@
# Escape carrier returns and single and double quotes for JavaScript segments.
def escape_javascript(js)
(js || '').gsub(/\r\n|\n|\r/, "\\n").gsub(/["']/) { |m| "\\#{m}" }
end
+ alias escape escape_javascript
# Converts a Ruby hash to a Javascript hash.
def hash_to_js(options)
'{' + options.map {|k, v| "#{k}:#{v}"}.join(', ') + '}'
@@ -28,10 +49,17 @@
# filename. Override if you don't like the defaults.
def name_to_jsfile(name)
"/js/#{name}.js"
end
+
+ # Generate javascript confirm code for links.
+
+ def confirm(text = 'Are you sure?')
+ %|onclick="return confirm('#{text}')"|
+ end
+
end
# Generates cliend side javascript.
module ScriptGenerator
@@ -402,7 +430,5 @@
end
end
end
-
-# * George Moschovitis <gm@navel.gr>