Skip to content

Commit

Permalink
Coffeescript and processor
Browse files Browse the repository at this point in the history
  • Loading branch information
bcardarella committed Jan 24, 2012
1 parent 5f4bedf commit 79a1e0f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
14 changes: 14 additions & 0 deletions coffeescript/processor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
$:.unshift(File.expand_path('../../lib', __FILE__))

require 'client_side_validations/formtastic/version'
require 'coffee_script'
require 'erb'

root_path = File.expand_path('../..', __FILE__)
file_name = 'rails.validations.formtastic'

template = ERB.new(File.open(File.join(root_path, 'coffeescript', "#{file_name}.coffee")).read)
javascript = CoffeeScript.compile(template.result(binding))
file = File.new(File.join(root_path, "vendor/assets/javascripts/#{file_name}.js"), 'w')
file << javascript
file.close
25 changes: 25 additions & 0 deletions coffeescript/rails.validations.formtastic.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
###
Client Side Validations - Formtastic - v<%= ClientSideValidations::Formtastic::VERSION %>
https://github.com/dockyard/client_side_validations-formtastic
Copyright (c) 2012 DockYard, LLC
Licensed under the MIT license
http://www.opensource.org/licenses/mit-license.php
###

ClientSideValidations.formBuilders['Formtastic::FormBuilder'] =
add: (element, settings, message) ->
if element.data('valid') != false
wrapper = element.closest('li')
errorElement = $('<p class="' + settings.inline_error_class + '">' + message + '</p>')
wrapper.addClass('error')
wrapper.append(errorElement)
else
element.parent().find('p.' + settings.inline_error_class).text(message)

remove: (element, settings) ->
wrapper = element.closest('li.error')
errorElement = wrapper.find('p.' + settings.inline_error_class)
wrapper.removeClass('error')
errorElement.remove()

0 comments on commit 79a1e0f

Please sign in to comment.