simple_form_custom_inputs 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 19b3ada295b61b7233df2896ad2db91187cf861d
4
- data.tar.gz: 11e3a7394298377fca09e9357111101e63a85dd5
3
+ metadata.gz: 92c5fb23cce41109af5e9501367ca431e3da28e1
4
+ data.tar.gz: 979d2579b862e722db590651e8f3511614bd3f93
5
5
  SHA512:
6
- metadata.gz: 44630a8757ad9581f5643d17f04733fe07141fccb05303e898ff3005167e250575096a3170873b2ebc036f840b8fc8253b1ee8b3c5c665d2d71181e2c52803e8
7
- data.tar.gz: 05722a1c0f9d3a03244a6c604ebc6aacb48a9ae4ab5d1297fa43e789fb149592a65093d81daa64dab4972f63bc9dc97de2569cb12361e50673fac362b292f4f1
6
+ metadata.gz: 1b85643e542e90a2a83fea5f086ca715cb0651f88e5283f209218cce152d4602b00ee894f45cf449947f6f6ccce98bd08a91325390e5320a0e4abfae882db9d2
7
+ data.tar.gz: be054daae5b8a6c90fd9c1a44a794a5c546122d9c6692bc9f7857ae2ff19847353e5b51c818cb267a17e7b1cded5e1fd06b54f46f696edc7d0e4784530b1e463
data/README.md CHANGED
@@ -5,8 +5,9 @@
5
5
  ## Availables inputs
6
6
 
7
7
  - [x] Switch/Toggle with Switchery
8
+ - [x] Masked inputs
8
9
  - [ ] Datepicker
9
- - [ ] Datetimepicker
10
+ - [ ] Datetimepicker
10
11
 
11
12
  ## Installation
12
13
 
@@ -18,6 +19,7 @@ gem 'simple_form_custom_inputs'
18
19
 
19
20
  source 'https://rails-assets.org' do
20
21
  gem 'rails-assets-switchery'
22
+ gem 'rails-assets-jquery.maskedinput'
21
23
  end
22
24
  ```
23
25
 
@@ -35,6 +37,7 @@ In app/assets/javascripts/application.js, you should add as follows:
35
37
  ```js
36
38
  //= require ...
37
39
  //= require switchery
40
+ //= require jquery.maskedinput
38
41
  //= require simple_form_custom_inputs
39
42
  //= require ...
40
43
  ```
@@ -53,14 +56,20 @@ Basic Example:
53
56
  <%= f.input :boolean, as: :switch %>
54
57
  ...
55
58
  <% end %>
59
+
60
+ <%= simple_form_for :example do |f| %>
61
+ ...
62
+ <%= f.input :phone, as: :masked, input_html: {data: {pattern: '(99) 99999-9999'}} %>
63
+ ...
64
+ <% end %>
56
65
  ```
57
66
 
58
- Want some more customization?
67
+ Want some more customization on Switch?
59
68
 
60
69
  ```erb
61
70
  <%= simple_form_for :example do |f| %>
62
71
  ...
63
- <%= f.input :boolean, as: :switch, input_html: {data: {color: '#FF0', secondary_color: '#0F0', jack_color: '#FFF', jack_secondary_color: '#000'}} %>
72
+ <%= f.input :boolean, as: :switch, input_html: {data: {color: '#FF0', secondary_color: '#0F0', jack_color: '#FFF', jack_secondary_color: '#000', size: 'small'}} %>
64
73
  ...
65
74
  <% end %>
66
75
  ```
data/example/Gemfile CHANGED
@@ -41,6 +41,7 @@ gem 'bootstrap-sass'
41
41
 
42
42
  source 'https://rails-assets.org' do
43
43
  gem 'rails-assets-switchery'
44
+ gem 'rails-assets-jquery.maskedinput'
44
45
  end
45
46
 
46
47
  group :development, :test do
data/example/Gemfile.lock CHANGED
@@ -115,6 +115,9 @@ GEM
115
115
  railties (= 5.0.2)
116
116
  sprockets-rails (>= 2.0.0)
117
117
  rails-assets-fastclick (0.6.11)
118
+ rails-assets-jquery (3.2.1)
119
+ rails-assets-jquery.maskedinput (1.4.1)
120
+ rails-assets-jquery (>= 1.8.3)
118
121
  rails-assets-switchery (0.8.2)
119
122
  rails-assets-fastclick (= 0.6.11)
120
123
  rails-assets-transitionize
@@ -190,6 +193,7 @@ DEPENDENCIES
190
193
  pry-rails
191
194
  puma (~> 3.0)
192
195
  rails (~> 5.0.2)
196
+ rails-assets-jquery.maskedinput!
193
197
  rails-assets-switchery!
194
198
  sass-rails (~> 5.0)
195
199
  simple_form
@@ -15,5 +15,6 @@
15
15
  //= require bootstrap-sprockets
16
16
  //= require turbolinks
17
17
  //= require switchery
18
+ //= require jquery.maskedinput
18
19
  //= require simple_form_custom_inputs
19
20
  //= require_tree .
@@ -0,0 +1,3 @@
1
+ # Place all the behaviors and hooks related to the matching controller here.
2
+ # All this logic will automatically be available in application.js.
3
+ # You can use CoffeeScript in this file: http://coffeescript.org/
@@ -0,0 +1,3 @@
1
+ // Place all the styles related to the Contacts controller here.
2
+ // They will automatically be included in application.css.
3
+ // You can use Sass (SCSS) here: http://sass-lang.com/
@@ -0,0 +1,74 @@
1
+ class ContactsController < ApplicationController
2
+ before_action :set_contact, only: [:show, :edit, :update, :destroy]
3
+
4
+ # GET /contacts
5
+ # GET /contacts.json
6
+ def index
7
+ @contacts = Contact.all
8
+ end
9
+
10
+ # GET /contacts/1
11
+ # GET /contacts/1.json
12
+ def show
13
+ end
14
+
15
+ # GET /contacts/new
16
+ def new
17
+ @contact = Contact.new
18
+ end
19
+
20
+ # GET /contacts/1/edit
21
+ def edit
22
+ end
23
+
24
+ # POST /contacts
25
+ # POST /contacts.json
26
+ def create
27
+ @contact = Contact.new(contact_params)
28
+
29
+ respond_to do |format|
30
+ if @contact.save
31
+ format.html { redirect_to @contact, notice: 'Contact was successfully created.' }
32
+ format.json { render :show, status: :created, location: @contact }
33
+ else
34
+ format.html { render :new }
35
+ format.json { render json: @contact.errors, status: :unprocessable_entity }
36
+ end
37
+ end
38
+ end
39
+
40
+ # PATCH/PUT /contacts/1
41
+ # PATCH/PUT /contacts/1.json
42
+ def update
43
+ respond_to do |format|
44
+ if @contact.update(contact_params)
45
+ format.html { redirect_to @contact, notice: 'Contact was successfully updated.' }
46
+ format.json { render :show, status: :ok, location: @contact }
47
+ else
48
+ format.html { render :edit }
49
+ format.json { render json: @contact.errors, status: :unprocessable_entity }
50
+ end
51
+ end
52
+ end
53
+
54
+ # DELETE /contacts/1
55
+ # DELETE /contacts/1.json
56
+ def destroy
57
+ @contact.destroy
58
+ respond_to do |format|
59
+ format.html { redirect_to contacts_url, notice: 'Contact was successfully destroyed.' }
60
+ format.json { head :no_content }
61
+ end
62
+ end
63
+
64
+ private
65
+ # Use callbacks to share common setup or constraints between actions.
66
+ def set_contact
67
+ @contact = Contact.find(params[:id])
68
+ end
69
+
70
+ # Never trust parameters from the scary internet, only allow the white list through.
71
+ def contact_params
72
+ params.require(:contact).permit(:name, :phone, :email)
73
+ end
74
+ end
@@ -1,2 +1,5 @@
1
1
  module ApplicationHelper
2
+ def br_phone_mask_pattern
3
+ "(99) 99999-9999"
4
+ end
2
5
  end
@@ -0,0 +1,2 @@
1
+ module ContactsHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ class Contact < ApplicationRecord
2
+ end
@@ -0,0 +1,2 @@
1
+ json.extract! contact, :id, :name, :phone, :email, :created_at, :updated_at
2
+ json.url contact_url(contact, format: :json)
@@ -0,0 +1,13 @@
1
+ <%= simple_form_for(@contact) do |f| %>
2
+ <%= f.error_notification %>
3
+
4
+ <div class="form-inputs">
5
+ <%= f.input :name %>
6
+ <%= f.input :phone, as: :masked, input_html: {data: {pattern: br_phone_mask_pattern}} %>
7
+ <%= f.input :email %>
8
+ </div>
9
+
10
+ <div class="form-actions">
11
+ <%= f.button :submit %>
12
+ </div>
13
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <h1>Editing Contact</h1>
2
+
3
+ <%= render 'form', contact: @contact %>
4
+
5
+ <%= link_to 'Show', @contact %> |
6
+ <%= link_to 'Back', contacts_path %>
@@ -0,0 +1,31 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <h1>Contacts</h1>
4
+
5
+ <table>
6
+ <thead>
7
+ <tr>
8
+ <th>Name</th>
9
+ <th>Phone</th>
10
+ <th>Email</th>
11
+ <th colspan="3"></th>
12
+ </tr>
13
+ </thead>
14
+
15
+ <tbody>
16
+ <% @contacts.each do |contact| %>
17
+ <tr>
18
+ <td><%= contact.name %></td>
19
+ <td><%= contact.phone %></td>
20
+ <td><%= contact.email %></td>
21
+ <td><%= link_to 'Show', contact %></td>
22
+ <td><%= link_to 'Edit', edit_contact_path(contact) %></td>
23
+ <td><%= link_to 'Destroy', contact, method: :delete, data: { confirm: 'Are you sure?' } %></td>
24
+ </tr>
25
+ <% end %>
26
+ </tbody>
27
+ </table>
28
+
29
+ <br>
30
+
31
+ <%= link_to 'New Contact', new_contact_path %>
@@ -0,0 +1 @@
1
+ json.array! @contacts, partial: 'contacts/contact', as: :contact
@@ -0,0 +1,5 @@
1
+ <h1>New Contact</h1>
2
+
3
+ <%= render 'form', contact: @contact %>
4
+
5
+ <%= link_to 'Back', contacts_path %>
@@ -0,0 +1,19 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <p>
4
+ <strong>Name:</strong>
5
+ <%= @contact.name %>
6
+ </p>
7
+
8
+ <p>
9
+ <strong>Phone:</strong>
10
+ <%= @contact.phone %>
11
+ </p>
12
+
13
+ <p>
14
+ <strong>Email:</strong>
15
+ <%= @contact.email %>
16
+ </p>
17
+
18
+ <%= link_to 'Edit', edit_contact_path(@contact) %> |
19
+ <%= link_to 'Back', contacts_path %>
@@ -0,0 +1 @@
1
+ json.partial! "contacts/contact", contact: @contact
@@ -1,4 +1,5 @@
1
1
  Rails.application.routes.draw do
2
+ resources :contacts
2
3
  resources :posts
3
4
  # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
4
5
  end
@@ -0,0 +1,11 @@
1
+ class CreateContacts < ActiveRecord::Migration[5.0]
2
+ def change
3
+ create_table :contacts do |t|
4
+ t.string :name
5
+ t.string :phone
6
+ t.string :email
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+ end
data/example/db/schema.rb CHANGED
@@ -10,7 +10,15 @@
10
10
  #
11
11
  # It's strongly recommended that you check this file into your version control system.
12
12
 
13
- ActiveRecord::Schema.define(version: 20170427011041) do
13
+ ActiveRecord::Schema.define(version: 20170427040213) do
14
+
15
+ create_table "contacts", force: :cascade do |t|
16
+ t.string "name"
17
+ t.string "phone"
18
+ t.string "email"
19
+ t.datetime "created_at", null: false
20
+ t.datetime "updated_at", null: false
21
+ end
14
22
 
15
23
  create_table "posts", force: :cascade do |t|
16
24
  t.string "title"
@@ -0,0 +1,48 @@
1
+ require 'test_helper'
2
+
3
+ class ContactsControllerTest < ActionDispatch::IntegrationTest
4
+ setup do
5
+ @contact = contacts(:one)
6
+ end
7
+
8
+ test "should get index" do
9
+ get contacts_url
10
+ assert_response :success
11
+ end
12
+
13
+ test "should get new" do
14
+ get new_contact_url
15
+ assert_response :success
16
+ end
17
+
18
+ test "should create contact" do
19
+ assert_difference('Contact.count') do
20
+ post contacts_url, params: { contact: { email: @contact.email, name: @contact.name, phone: @contact.phone } }
21
+ end
22
+
23
+ assert_redirected_to contact_url(Contact.last)
24
+ end
25
+
26
+ test "should show contact" do
27
+ get contact_url(@contact)
28
+ assert_response :success
29
+ end
30
+
31
+ test "should get edit" do
32
+ get edit_contact_url(@contact)
33
+ assert_response :success
34
+ end
35
+
36
+ test "should update contact" do
37
+ patch contact_url(@contact), params: { contact: { email: @contact.email, name: @contact.name, phone: @contact.phone } }
38
+ assert_redirected_to contact_url(@contact)
39
+ end
40
+
41
+ test "should destroy contact" do
42
+ assert_difference('Contact.count', -1) do
43
+ delete contact_url(@contact)
44
+ end
45
+
46
+ assert_redirected_to contacts_url
47
+ end
48
+ end
@@ -0,0 +1,11 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2
+
3
+ one:
4
+ name: MyString
5
+ phone: MyString
6
+ email: MyString
7
+
8
+ two:
9
+ name: MyString
10
+ phone: MyString
11
+ email: MyString
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class ContactTest < ActiveSupport::TestCase
4
+ # test "the truth" do
5
+ # assert true
6
+ # end
7
+ end
@@ -0,0 +1,7 @@
1
+ class MaskedInput < SimpleForm::Inputs::StringInput
2
+ def input(wrapper_options)
3
+ input_html_options[:data] ||= {}
4
+ input_html_options[:class] << 'masked'
5
+ super
6
+ end
7
+ end
@@ -1,3 +1,3 @@
1
1
  module SimpleFormCustomInputs
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,6 +1,7 @@
1
1
  require "simple_form_custom_inputs/version"
2
2
 
3
3
  autoload :SwitchInput, "simple_form_custom_inputs/simple_form/switch_input"
4
+ autoload :MaskedInput, "simple_form_custom_inputs/simple_form/masked_input"
4
5
 
5
6
  module SimpleFormCustomInputs
6
7
  class Engine < ::Rails::Engine; end
@@ -11,8 +11,15 @@ var initSwitchery = function() {
11
11
  }
12
12
  }
13
13
 
14
+ var initMasks = function() {
15
+ var input = $('.masked input');
16
+ var pattern = input.data('pattern');
17
+ input.mask(pattern);
18
+ }
19
+
14
20
  var ready = function() {
15
21
  initSwitchery();
22
+ initMasks();
16
23
  };
17
24
 
18
25
  if (typeof Turbolinks == "undefined") {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_form_custom_inputs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcelo Barreto
@@ -61,22 +61,35 @@ files:
61
61
  - example/app/assets/javascripts/application.js
62
62
  - example/app/assets/javascripts/cable.js
63
63
  - example/app/assets/javascripts/channels/.keep
64
+ - example/app/assets/javascripts/contacts.coffee
64
65
  - example/app/assets/javascripts/posts.coffee
65
66
  - example/app/assets/stylesheets/application.scss
67
+ - example/app/assets/stylesheets/contacts.scss
66
68
  - example/app/assets/stylesheets/posts.scss
67
69
  - example/app/assets/stylesheets/scaffolds.scss
68
70
  - example/app/channels/application_cable/channel.rb
69
71
  - example/app/channels/application_cable/connection.rb
70
72
  - example/app/controllers/application_controller.rb
71
73
  - example/app/controllers/concerns/.keep
74
+ - example/app/controllers/contacts_controller.rb
72
75
  - example/app/controllers/posts_controller.rb
73
76
  - example/app/helpers/application_helper.rb
77
+ - example/app/helpers/contacts_helper.rb
74
78
  - example/app/helpers/posts_helper.rb
75
79
  - example/app/jobs/application_job.rb
76
80
  - example/app/mailers/application_mailer.rb
77
81
  - example/app/models/application_record.rb
78
82
  - example/app/models/concerns/.keep
83
+ - example/app/models/contact.rb
79
84
  - example/app/models/post.rb
85
+ - example/app/views/contacts/_contact.json.jbuilder
86
+ - example/app/views/contacts/_form.html.erb
87
+ - example/app/views/contacts/edit.html.erb
88
+ - example/app/views/contacts/index.html.erb
89
+ - example/app/views/contacts/index.json.jbuilder
90
+ - example/app/views/contacts/new.html.erb
91
+ - example/app/views/contacts/show.html.erb
92
+ - example/app/views/contacts/show.json.jbuilder
80
93
  - example/app/views/layouts/application.html.erb
81
94
  - example/app/views/layouts/mailer.html.erb
82
95
  - example/app/views/layouts/mailer.text.erb
@@ -122,6 +135,7 @@ files:
122
135
  - example/config/secrets.yml
123
136
  - example/config/spring.rb
124
137
  - example/db/migrate/20170427011041_create_posts.rb
138
+ - example/db/migrate/20170427040213_create_contacts.rb
125
139
  - example/db/schema.rb
126
140
  - example/db/seeds.rb
127
141
  - example/lib/assets/.keep
@@ -136,20 +150,24 @@ files:
136
150
  - example/public/favicon.ico
137
151
  - example/public/robots.txt
138
152
  - example/test/controllers/.keep
153
+ - example/test/controllers/contacts_controller_test.rb
139
154
  - example/test/controllers/posts_controller_test.rb
140
155
  - example/test/fixtures/.keep
156
+ - example/test/fixtures/contacts.yml
141
157
  - example/test/fixtures/files/.keep
142
158
  - example/test/fixtures/posts.yml
143
159
  - example/test/helpers/.keep
144
160
  - example/test/integration/.keep
145
161
  - example/test/mailers/.keep
146
162
  - example/test/models/.keep
163
+ - example/test/models/contact_test.rb
147
164
  - example/test/models/post_test.rb
148
165
  - example/test/test_helper.rb
149
166
  - example/tmp/.keep
150
167
  - example/vendor/assets/javascripts/.keep
151
168
  - example/vendor/assets/stylesheets/.keep
152
169
  - lib/simple_form_custom_inputs.rb
170
+ - lib/simple_form_custom_inputs/simple_form/masked_input.rb
153
171
  - lib/simple_form_custom_inputs/simple_form/switch_input.rb
154
172
  - lib/simple_form_custom_inputs/version.rb
155
173
  - screenshot.png