Skip to content

Commit

Permalink
Rename MagicWord to Comply
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobaweiss committed Jun 11, 2014
1 parent edd7a29 commit 3572e89
Show file tree
Hide file tree
Showing 29 changed files with 71 additions and 71 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source "https://rubygems.org"

# Declare your gem's dependencies in magic_word.gemspec.
# Declare your gem's dependencies in comply.gemspec.
# Bundler will treat runtime dependencies like base dependencies, and
# development dependencies will be added by default to the :development group.
gemspec
Expand Down
8 changes: 4 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
magic_word (0.0.1)
comply (0.0.2)
coffee-rails
rails

Expand Down Expand Up @@ -44,7 +44,7 @@ GEM
coffee-script-source (1.7.0)
diff-lcs (1.2.5)
erubis (2.7.0)
execjs (2.0.2)
execjs (2.2.0)
hike (1.2.3)
i18n (0.6.9)
jasmine-core (2.0.0)
Expand All @@ -61,7 +61,7 @@ GEM
minitest (4.7.5)
multi_json (1.10.0)
phantomjs (1.9.7.0)
polyglot (0.3.4)
polyglot (0.3.5)
pry (0.9.12.6)
coderay (~> 1.0)
method_source (~> 0.8)
Expand Down Expand Up @@ -118,8 +118,8 @@ PLATFORMS
ruby

DEPENDENCIES
comply!
jasmine-rails
magic_word!
pry
rspec-rails (~> 2.14)
sqlite3
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# MagicWord
# Comply
Server-side ActiveRecord validations, all up in your client-side HTML.

## Intention and Purpose
Expand All @@ -9,23 +9,23 @@ Though it's better, doing that still requires duplicating your validations on th
The solution offered here is combine the server-side validations with inline error messages on the form. This is done by creating an API for validating your objects. When triggered, the form is serialized and sent to the API endpoint, where it is instantiated as your ActiveRecord model, and validations are run. The API returns the instance's error messages, which the form uses to determine if the described object is valid.

## Basic Usage
Include Magic Word in your gemfile:
Include Comply in your gemfile:
```ruby
gem 'magic_word'
gem 'comply'
```
If you are using Rails 3, you need to include `strong_parameters`
```ruby
gem 'magic_word'
gem 'comply'
gem 'strong_parameters'
```
Mount the engine in your `routes.rb`:
```ruby
mount MagicWord::Engine => '/magic_word'
mount Comply::Engine => '/comply'
```
Require the javascript files & dependencies in the form's corresponding javascript file (requires Asset Pipeline):
```js
//= require jquery
//= require magic_word
//= require comply
```

In your form:
Expand Down Expand Up @@ -100,11 +100,11 @@ Normally, a multiparameter input won't validate until all of its fields have bee
```

## Customizing the ValidationMessage class
If you don't want to use the default `MagicWord.ValidationMessage`, which is responsible for putting the validation message tag on the page and handling the display of messages, great news: you can overwrite it!
If you don't want to use the default `Comply.ValidationMessage`, which is responsible for putting the validation message tag on the page and handling the display of messages, great news: you can overwrite it!

After you've included MagicWord in the Asset Pipeline, feel free to extend it! For example (in `foo.js.coffee`):
After you've included Comply in the Asset Pipeline, feel free to extend it! For example (in `foo.js.coffee`):
```coffeescript
class MagicWord.ValidationMessage extends MagicWord.BaseValidationMessage
class Comply.ValidationMessage extends Comply.BaseValidationMessage
constructor: (@$el) ->
super
console.log 'We can build him. We have the technology.'
Expand All @@ -126,11 +126,11 @@ class MagicWord.ValidationMessage extends MagicWord.BaseValidationMessage
If you would like to mount the engine under a different namespace, all you need to do is add the engine path to the javascript object:
Routes file:
```ruby
mount MagicWord::Engine => '/joanie_loves_chachi'
mount Comply::Engine => '/joanie_loves_chachi'
```
Javascript file:
```javascript
//= require magic_word
//= require comply

MagicWord.enginePath = 'joanie_loves_chachi';
Comply.enginePath = 'joanie_loves_chachi';
```
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require 'rdoc/task'

RDoc::Task.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'MagicWord'
rdoc.title = 'Comply'
rdoc.options << '--line-numbers'
rdoc.rdoc_files.include('README.rdoc')
rdoc.rdoc_files.include('lib/**/*.rb')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class MagicWord.BaseValidationMessage
class Comply.BaseValidationMessage
constructor: (@$el) ->
if multiparam = @$el.data('multiparam')
selector = "[data-multiparam=#{multiparam}].validation-msg"
Expand Down
3 changes: 3 additions & 0 deletions app/assets/javascripts/comply/config.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
window.Comply = {
enginePath: 'comply',
}
4 changes: 4 additions & 0 deletions app/assets/javascripts/comply/index.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#= require comply/config
#= require_tree .

$ -> $('[data-validate-model]').each -> new Comply.ValidatableForm $(this)
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
class MagicWord.ValidatableForm
class Comply.ValidatableForm
constructor: (@$form) ->
@inputs = @_inputs()
@model = @$form.data('validate-model')
@$button = @$form.find('[type=submit]')
@validationRoute = "/#{MagicWord.enginePath}/validations"
@validationRoute = "/#{Comply.enginePath}/validations"
@$button.click @validateInputs
@$button.attr('disabled', false).removeClass('disabled')

Expand All @@ -27,7 +27,7 @@ class MagicWord.ValidatableForm

_inputs: ->
for input in @$form.find('[data-validate][name]')
new MagicWord.ValidatableInput $(input), this
new Comply.ValidatableInput $(input), this

_isSuccess: (input, response) ->
if !!@_responseValue(input, response) then 'error' else 'success'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class MagicWord.ValidatableInput
class Comply.ValidatableInput
constructor: (@$el, @form) ->
parts = @$el.attr('name').replace(/\]/g, '').split('[')
@model = parts[0]
Expand All @@ -7,7 +7,7 @@ class MagicWord.ValidatableInput
@timeoutLength = @$el.data('validate-timeout') or 500
@successMessage = @$el.data('validate-success')
@dependency = @_dependency()
@message = new MagicWord.ValidationMessage @$el
@message = new Comply.ValidationMessage @$el
@$el.bind @event, @validate

validate: =>
Expand All @@ -22,7 +22,7 @@ class MagicWord.ValidatableInput
#private

_dependency: ->
new MagicWord.ValidatableInput($("#{@$el.data('validate-with')}[name]"), @form) if @$el.data('validate-with')?
new Comply.ValidatableInput($("#{@$el.data('validate-with')}[name]"), @form) if @$el.data('validate-with')?

_forceValidate: -> @forceValidate or= @$el.data('validate-force')

Expand Down
1 change: 1 addition & 0 deletions app/assets/javascripts/comply/validation_message.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class Comply.ValidationMessage extends Comply.BaseValidationMessage
3 changes: 0 additions & 3 deletions app/assets/javascripts/magic_word/config.js.coffee

This file was deleted.

4 changes: 0 additions & 4 deletions app/assets/javascripts/magic_word/index.js.coffee

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module MagicWord
module Comply
class ApplicationController < ActionController::Base
end
end
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module MagicWord
class ValidationsController < MagicWord::ApplicationController
module Comply
class ValidationsController < Comply::ApplicationController
before_filter :require_model, :require_fields

def show
Expand Down
8 changes: 4 additions & 4 deletions magic_word.gemspec → comply.gemspec
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
$:.push File.expand_path('../lib', __FILE__)

require 'magic_word/version'
require 'comply/version'

Gem::Specification.new do |s|
s.name = 'magic_word'
s.version = MagicWord::VERSION
s.name = 'comply'
s.version = Comply::VERSION
s.authors = ['@jacobaweiss', '@andyjbas', '@azach']
s.email = ['jack@lumoslabs.com']
s.homepage = 'http://www.github.com/lumoslabs/magic_word'
s.homepage = 'http://www.github.com/lumoslabs/comply'
s.summary = 'Inline validation of your ActiveRecord models via the AJAX internets'
s.description = 'Validate your ActiveRecord models on the client, showing their error and success messages by providing a validation controller.'

Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
MagicWord::Engine.routes.draw do
Comply::Engine.routes.draw do
match '/validations' => 'validations#show', via: :get
end
4 changes: 4 additions & 0 deletions lib/comply.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require 'comply/engine'

module Comply
end
5 changes: 5 additions & 0 deletions lib/comply/engine.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Comply
class Engine < ::Rails::Engine
isolate_namespace Comply
end
end
2 changes: 1 addition & 1 deletion lib/magic_word/version.rb → lib/comply/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module MagicWord
module Comply
VERSION = '0.0.2'
end
4 changes: 0 additions & 4 deletions lib/magic_word.rb

This file was deleted.

5 changes: 0 additions & 5 deletions lib/magic_word/engine.rb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper'

describe MagicWord::ValidationsController do
routes { MagicWord::Engine.routes }
describe Comply::ValidationsController do
routes { Comply::Engine.routes }

describe 'POST #create' do
let(:model) { 'movie' }
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy/app/assets/javascripts/movies.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
// All this logic will automatically be available in application.js.

//= require jquery
//= require magic_word
//= require comply
2 changes: 1 addition & 1 deletion spec/dummy/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require 'rails/all'

Bundler.require(*Rails.groups)
require "magic_word"
require 'comply'

module Dummy
class Application < Rails::Application
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy/config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Rails.application.routes.draw do
mount JasmineRails::Engine => '/specs' if defined?(JasmineRails)
mount MagicWord::Engine => '/magic_word'
mount Comply::Engine => '/comply'

resources :movies
end
12 changes: 6 additions & 6 deletions spec/dummy/spec/javascripts/validatable_form_spec.js.coffee
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
#= require magic_word
#= require comply

describe 'ValidatableForm', ->
beforeEach ->
@model = 'movie'
@value = 'Gymkata'
input = "<input data-validate='true' name='movie[title]' value='#{@value}' type='text'>"
@formjQuery = $("<form data-validate-model='#{@model}'>#{input}</form>")
@form = new MagicWord.ValidatableForm @formjQuery
@form = new Comply.ValidatableForm @formjQuery

describe '#constructor', ->
it 'sets the model to validate', ->
expect(@form.model).toBe(@model)

it 'sets the default validation path', ->
expect(@form.validationRoute).toBe('/magic_word/validations')
expect(@form.validationRoute).toBe('/comply/validations')

describe 'when MagicWord.enginePath has been set', ->
describe 'when Comply.enginePath has been set', ->
beforeEach ->
MagicWord.enginePath = 'wally_world'
@form = new MagicWord.ValidatableForm @formjQuery
Comply.enginePath = 'wally_world'
@form = new Comply.ValidatableForm @formjQuery

it 'sets the given validation path', ->
expect(@form.validationRoute).toBe('/wally_world/validations')
Expand Down
14 changes: 7 additions & 7 deletions spec/dummy/spec/javascripts/validatable_input_spec.js.coffee
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#= require magic_word
#= require comply

describe 'ValidatableInput', ->
beforeEach ->
@defaultTimeoutLength = 500
@form = validate: ->
@inputjQuery = $("<input name='foo[bar]'/>")
@input = new MagicWord.ValidatableInput @inputjQuery, @form
@input = new Comply.ValidatableInput @inputjQuery, @form

describe '#constructor', ->
it 'sets the default timeout length to 500ms', ->
Expand All @@ -17,15 +17,15 @@ describe 'ValidatableInput', ->
describe 'when timeout length is set on the input', ->
beforeEach ->
@inputjQuery = $("<input data-validate-timeout='666' name='foo[bar]' value='' />")
@input = new MagicWord.ValidatableInput @inputjQuery, @form
@input = new Comply.ValidatableInput @inputjQuery, @form

it 'uses the timeout length provided', ->
expect(@input.timeoutLength).toBe(666)

describe "when an alternate event is provided", ->
beforeEach ->
@inputjQuery = $("<input data-validate-event='input keydown' name='foo[bar]' />")
@input = new MagicWord.ValidatableInput @inputjQuery, @form
@input = new Comply.ValidatableInput @inputjQuery, @form

it 'uses the event provided', ->
expect(@input.event).toBe("input keydown")
Expand Down Expand Up @@ -59,7 +59,7 @@ describe 'ValidatableInput', ->

describe 'with a dependency', ->
beforeEach ->
@dependency = new MagicWord.ValidatableInput $("<input name='foo[baz]'/>"), @form
@dependency = new Comply.ValidatableInput $("<input name='foo[baz]'/>"), @form
spyOn(@input, '_dependency').and.returnValue(@dependency)
spyOn(@input.form, 'validate')

Expand All @@ -74,15 +74,15 @@ describe 'ValidatableInput', ->
describe 'with forceValidate set', ->
beforeEach ->
@inputjQuery = $("<input data-validate-force='true' name='foo[bar]'/>")
@input = new MagicWord.ValidatableInput @inputjQuery, @form
@input = new Comply.ValidatableInput @inputjQuery, @form

it 'is validatable', ->
expect(@input._validatable()).toBe(true)

describe 'when not a multiparameter input', ->
beforeEach ->
@inputjQuery = $("<input name='foo[bar]'/>")
@input = new MagicWord.ValidatableInput @inputjQuery, @form
@input = new Comply.ValidatableInput @inputjQuery, @form

it 'is true if forceValidate is set', ->
expect(@input._validatable()).toBe(true)
4 changes: 2 additions & 2 deletions spec/dummy/spec/javascripts/validation_message_spec.js.coffee
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#= require magic_word
#= require comply

describe 'ValidationMessage', ->
beforeEach ->
@messageBox = $('<div>Stuff</div>')
@m = new MagicWord.ValidationMessage @messageBox
@m = new Comply.ValidationMessage @messageBox

describe '#constructor', ->
it 'creates a validation message div', ->
Expand Down

0 comments on commit 3572e89

Please sign in to comment.