Class: JavascriptWriter
- Inherits:
-
Object
- Object
- JavascriptWriter
- Defined in:
- app/writers/javascript_writer.rb
Instance Attribute Summary collapse
-
#data_table ⇒ Object
readonly
Returns the value of attribute data_table.
Instance Method Summary collapse
-
#initialize(data_table) ⇒ JavascriptWriter
constructor
A new instance of JavascriptWriter.
- #write ⇒ Object
Constructor Details
#initialize(data_table) ⇒ JavascriptWriter
Returns a new instance of JavascriptWriter.
4 5 6 |
# File 'app/writers/javascript_writer.rb', line 4 def initialize(data_table) @data_table = data_table end |
Instance Attribute Details
#data_table ⇒ Object (readonly)
Returns the value of attribute data_table.
2 3 4 |
# File 'app/writers/javascript_writer.rb', line 2 def data_table @data_table end |
Instance Method Details
#write ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/writers/javascript_writer.rb', line 8 def write FileUtils.mkdir_p('app/assets/javascripts/gatherable') if File.exists?(javascript_class) puts "Found #{javascript_class}. Skipping" return end File.open(javascript_class, 'w') do |f| if Gatherable.config.prefixed_resources.include?(data_table.name) function_arg = 'global_identifier, ' path_arg = ' + global_identifier + /' end f.puts "var \#{data_table.class_name} = {\ncreate: function(\#{function_arg}options){\n $.ajax({\n url: '/gatherable/\#{path_arg}\#{data_table.name.to_s.pluralize}',\n method: 'POST',\n data: { \#{data_table.name}: options }\n });\n},\nget: function(global_identifier, id) {\n $.ajax({\n url: '/gatherable/\#{path_arg}\#{data_table.name}/' + options[\#{data_table.name}_id]\n });\n}\n}\n class\n end\n puts \"created \#{javascript_class}\" if File.exists?(javascript_class)\nend\n" |