phantom_forms 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bee70e7bd5539ba85636c0fd5dbedf3f3217fd91
4
+ data.tar.gz: e0d00e0efa68e6e9e84be35c471168445ee3c386
5
+ SHA512:
6
+ metadata.gz: 28c9c1a0091c6695f4c1792e78983696be2199fdb4b93ccdf07efaae109ea0e052badf08c80b6104254320cec397f40bab6a60341b2bf2b938ec97ff35a500ae
7
+ data.tar.gz: ada080a157947d2fc00a4174dc0d28a191ebfc96ebcad418a4763b09840d08e8128489016112138cdfadc6e7aea96a3071f71e38530a86bd4a725c11162571a1
data/README.md ADDED
@@ -0,0 +1 @@
1
+ Helpers for Twitter Bootstrap v3.
@@ -0,0 +1,4 @@
1
+ module PhantomForms
2
+ class Engine < Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,50 @@
1
+ module PhantomForms
2
+ module FormBuilders
3
+ class ValidateFormBuilder < ActionView::Helpers::FormBuilder
4
+
5
+ FORM_HELPERS = %w{text_field password_field text_area file_field
6
+ number_field email_field telephone_field phone_field url_field
7
+ select collection_select date_select time_select datetime_select}
8
+
9
+ delegate :content_tag, to: :@template
10
+
11
+ def initialize(*)
12
+ super
13
+ @help_tag, @help_css = if options.fetch(:help, '').to_sym == :block
14
+ [:p, 'help-block']
15
+ else
16
+ [:span, 'help-inline']
17
+ end
18
+ end
19
+
20
+ FORM_HELPERS.each do |method_name|
21
+ define_method(method_name) do |name, *args|
22
+ options = args.extract_options!.symbolize_keys!
23
+ content_tag :div, class: "form-group" do
24
+ label(name, options[:label], class: 'control-label') +
25
+ content_tag(:div, class: 'controls') do
26
+ help = object.errors[name].any? ? object.errors[name].join(', ') : options[:help]
27
+ help = content_tag(@help_tag, class: @help_css) { help } if help
28
+ options[:class] = options[:class].to_s + " form-control"
29
+ args << options.except(:label, :help)
30
+ super(name, *args) + help
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ def check_box(name, *args)
37
+ options = args.extract_options!.symbolize_keys!
38
+ content_tag :div, class: "control-group#{(' error' if object.errors[name].any?)}" do
39
+ content_tag(:div, class: 'controls') do
40
+ args << options.except(:label, :help)
41
+ html = super(name, *args) + ' ' + options[:label]
42
+ label(name, html, class: 'checkbox')
43
+ end
44
+ end
45
+ end
46
+
47
+ end
48
+
49
+ end
50
+ end
@@ -0,0 +1,112 @@
1
+ module PhantomForms
2
+ module Helper
3
+
4
+ def remote_form_for(object, options = {}, &block)
5
+ options[:validate] = true
6
+ options[:builder] = PhantomForms::FormBuilders::ValidateFormBuilder
7
+ options[:remote] = true
8
+ options[:html] = {:class => 'remote-form form'}
9
+ content_tag :div, class: "col-md-12" do
10
+ content_tag :div, class: "well" do
11
+ form_for(object, options, &block)
12
+ end
13
+ end
14
+ end
15
+
16
+ def remote_form_panel_for(object, panel_title = nil, options = {}, &block)
17
+ options[:validate] = true
18
+ options[:builder] = PhantomForms::FormBuilders::ValidateFormBuilder
19
+ options[:remote] = true
20
+ options[:html] = {:class => 'remote-form form'}
21
+ content_tag :div, class: "col-md-12" do
22
+ content_tag :div, class: "panel panel-primary" do
23
+ [
24
+ if panel_title
25
+ content_tag :div, class: "panel-heading" do
26
+ content_tag :h3, class: "panel-title" do
27
+ panel_title
28
+ end
29
+ end
30
+ end,
31
+ content_tag(:div, class: "panel-body") do
32
+ form_for(object, options, &block)
33
+ end
34
+ ].join.html_safe
35
+ end
36
+ end
37
+ end
38
+
39
+ def normal_form_for(object, options = {}, &block)
40
+ options[:validate] = true
41
+ options[:builder] = PhantomForms::FormBuilders::ValidateFormBuilder
42
+ options[:html] = {:class => 'normal-form form'}
43
+ content_tag :div, class: "row" do
44
+ content_tag :div, class: "span12 well" do
45
+ form_for(object, options, &block)
46
+ end
47
+ end
48
+ end
49
+
50
+ def modal_form_for(object, options = {}, &block)
51
+ options[:validate] = true
52
+ options[:builder] = PhantomForms::FormBuilders::ValidateFormBuilder
53
+ options[:html] = {:'data-type' => 'script', :class => 'remote-form'}
54
+ options[:remote] = true
55
+ form_for(object, options, &block)
56
+ end
57
+
58
+ def normal_modal_form_for(object, options = {}, &block)
59
+ options[:validate] = true
60
+ options[:builder] = PhantomForms::FormBuilders::ValidateFormBuilder
61
+ options[:html] = {:'data-type' => 'script', :class => 'normal-form'}
62
+ form_for(object, options, &block)
63
+ end
64
+
65
+ def buttons_for(object, options = {})
66
+ object_name = get_class(object)
67
+ object_class = options[:nested_id] || object_name
68
+
69
+ locale_name = object_name.underscore
70
+ locale = options[:label] || t("#{locale_name}.save")
71
+
72
+ content_tag :div, :class => 'row' do
73
+ [
74
+ content_tag(:div, :class => 'col-md-9') do
75
+ concat submit_button( locale , :id => "submit-#{object_class}-button")
76
+ end,
77
+ content_tag(:div, :class => 'col-md-3') do
78
+ concat link_to_cancel( :id => "cancel-#{object_class}-link")
79
+ end
80
+ ].join.html_safe
81
+ end
82
+ end
83
+
84
+ def modal_buttons_for(object, options = {})
85
+ object_name = get_class(object)
86
+ object_class = options[:nested_id] || object_name
87
+
88
+ locale_name = object_name.underscore
89
+ locale = options[:label] || t("#{locale_name}.save")
90
+
91
+ content_tag :div, :class => 'row' do
92
+ content_tag :div, :class => 'col-md-12' do
93
+ concat submit_button( locale , :id => "submit-#{object_class}-button")
94
+ concat link_to_modal_cancel( :id => "cancel-#{object_class}-link")
95
+ end
96
+ end
97
+ end
98
+
99
+
100
+ private
101
+
102
+ def get_class(object)
103
+ object_class_name = object.class.to_s.underscore.dasherize.split('/').last
104
+ if object_class_name.include? '-decorator'
105
+ object_class_name.split('-decorator').first
106
+ else
107
+ object_class_name
108
+ end
109
+ end
110
+
111
+ end
112
+ end
@@ -0,0 +1,8 @@
1
+ require 'phantom_forms/helper'
2
+ require 'phantom_forms/engine'
3
+ require 'phantom_forms/form_builders/validate_form_builder'
4
+
5
+ module PhantomForms
6
+ end
7
+
8
+ ActionView::Base.send :include, PhantomForms::Helper
@@ -0,0 +1,24 @@
1
+ formBuilder =
2
+ add: (element, settings, message) ->
3
+ if element.data("valid") isnt false
4
+ element.data "valid", false
5
+ element.parent().parent().addClass "error"
6
+ element.parent().find(".message").addClass "error help-inline"
7
+ $('<span/>').addClass('help-inline').text(message).appendTo(element.parent())
8
+
9
+ remove: (element, settings) ->
10
+ element.parent().parent().removeClass('error')
11
+ element.parent().find(".message").removeClass "error help-inline"
12
+ element.parent().find('span.help-inline').remove()
13
+ element.data "valid", true
14
+
15
+
16
+ window.Rails4ClientSideValidations.formBuilders["PhantomForms::FormBuilders::ValidateFormBuilder"] = formBuilder
17
+
18
+ $ ->
19
+
20
+ window.Rails4ClientSideValidations.callbacks.element.fail = (element, message, callback) ->
21
+ callback()
22
+ if element.data("valid") isnt false
23
+ element.parent().parent().addClass "error"
24
+ element.parent().find(".message").addClass "error help-inline"
@@ -0,0 +1,2 @@
1
+ //= require rails.validations
2
+ //= require forms
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: phantom_forms
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.5
5
+ platform: ruby
6
+ authors:
7
+ - Vassil Kalkov
8
+ - Rei Kagetsuki
9
+ - Nakaya Yukiharu
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2013-09-23 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rails4_client_side_validations
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - '>='
27
+ - !ruby/object:Gem::Version
28
+ version: '0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: rails
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: phantom_helpers
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ~>
48
+ - !ruby/object:Gem::Version
49
+ version: 0.0.6
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ version: 0.0.6
57
+ description: rails helpers for bootstrap 3
58
+ email: info@genshin.org
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - lib/phantom_forms/form_builders/validate_form_builder.rb
64
+ - lib/phantom_forms/engine.rb
65
+ - lib/phantom_forms/helper.rb
66
+ - lib/phantom_forms.rb
67
+ - vendor/assets/javascripts/forms.js.coffee
68
+ - vendor/assets/javascripts/phantom_forms.js
69
+ - README.md
70
+ homepage: http://github.com/Genshin/phantom_forms
71
+ licenses:
72
+ - GNU GPL-3
73
+ - AGPL-3
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '>='
82
+ - !ruby/object:Gem::Version
83
+ version: 1.8.7
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements:
90
+ - none
91
+ rubyforge_project:
92
+ rubygems_version: 2.0.3
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Phantom Forms
96
+ test_files: []