bootstrap_form_legacy 4.0.1.dev

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -0
  3. data/.travis.yml +29 -0
  4. data/CHANGELOG.md +207 -0
  5. data/CONTRIBUTING.md +57 -0
  6. data/Dangerfile +54 -0
  7. data/Gemfile +21 -0
  8. data/LICENSE.txt +20 -0
  9. data/README.md +647 -0
  10. data/Rakefile +27 -0
  11. data/app/assets/stylesheets/rails_bootstrap_forms.css +10 -0
  12. data/bootstrap_form.gemspec +26 -0
  13. data/demo/README.md +17 -0
  14. data/demo/Rakefile +6 -0
  15. data/demo/app/controllers/application_controller.rb +2 -0
  16. data/demo/app/controllers/bootstrap_controller.rb +16 -0
  17. data/demo/app/helpers/bootstrap_helper.rb +23 -0
  18. data/demo/app/models/address.rb +3 -0
  19. data/demo/app/models/application_record.rb +3 -0
  20. data/demo/app/models/faux_user.rb +9 -0
  21. data/demo/app/models/super_user.rb +2 -0
  22. data/demo/app/models/user.rb +9 -0
  23. data/demo/app/views/bootstrap/form.html.erb +53 -0
  24. data/demo/app/views/layouts/application.html.erb +65 -0
  25. data/demo/bin/bundle +3 -0
  26. data/demo/bin/rails +4 -0
  27. data/demo/bin/rake +4 -0
  28. data/demo/bin/setup +36 -0
  29. data/demo/bin/update +31 -0
  30. data/demo/bin/yarn +11 -0
  31. data/demo/config.ru +5 -0
  32. data/demo/config/application.rb +24 -0
  33. data/demo/config/boot.rb +5 -0
  34. data/demo/config/database.yml +21 -0
  35. data/demo/config/environment.rb +5 -0
  36. data/demo/config/environments/development.rb +60 -0
  37. data/demo/config/environments/test.rb +48 -0
  38. data/demo/config/initializers/application_controller_renderer.rb +8 -0
  39. data/demo/config/initializers/assets.rb +14 -0
  40. data/demo/config/initializers/backtrace_silencers.rb +7 -0
  41. data/demo/config/initializers/cookies_serializer.rb +5 -0
  42. data/demo/config/initializers/filter_parameter_logging.rb +4 -0
  43. data/demo/config/initializers/inflections.rb +16 -0
  44. data/demo/config/initializers/mime_types.rb +4 -0
  45. data/demo/config/initializers/wrap_parameters.rb +14 -0
  46. data/demo/config/locales/en.yml +33 -0
  47. data/demo/config/puma.rb +56 -0
  48. data/demo/config/routes.rb +5 -0
  49. data/demo/config/spring.rb +6 -0
  50. data/demo/config/storage.yml +35 -0
  51. data/demo/db/schema.rb +24 -0
  52. data/demo/log/.keep +0 -0
  53. data/demo/package.json +5 -0
  54. data/demo/public/favicon.ico +0 -0
  55. data/lib/bootstrap_form.rb +13 -0
  56. data/lib/bootstrap_form/aliasing.rb +35 -0
  57. data/lib/bootstrap_form/form_builder.rb +564 -0
  58. data/lib/bootstrap_form/helper.rb +59 -0
  59. data/lib/bootstrap_form/helpers/bootstrap.rb +99 -0
  60. data/lib/bootstrap_form/version.rb +3 -0
  61. metadata +120 -0
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'BootstrapForm'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ require 'bundler/gem_tasks'
18
+
19
+ require 'rake/testtask'
20
+
21
+ Rake::TestTask.new(:test) do |t|
22
+ t.libs << 'test'
23
+ t.pattern = 'test/**/*_test.rb'
24
+ t.verbose = false
25
+ end
26
+
27
+ task default: :test
@@ -0,0 +1,10 @@
1
+ .rails-bootstrap-forms-date-select select,
2
+ .rails-bootstrap-forms-time-select select,
3
+ .rails-bootstrap-forms-datetime-select select {
4
+ display: inline-block;
5
+ width: auto;
6
+ }
7
+
8
+ .rails-bootstrap-forms-error-summary {
9
+ margin-top: 10px;
10
+ }
@@ -0,0 +1,26 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ require "bootstrap_form/version"
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "bootstrap_form_legacy"
8
+ s.version = BootstrapForm::VERSION
9
+ s.authors = ["Stephen Potenza", "Carlos Lopes"]
10
+ s.email = ["potenza@gmail.com", "carlos.el.lopes@gmail.com"]
11
+ s.homepage = "https://github.com/bootstrap-ruby/bootstrap_form"
12
+ s.summary = "Rails form builder that makes it easy to style forms using "\
13
+ "Bootstrap 4"
14
+ s.description = "bootstrap_form is a rails form builder that makes it super "\
15
+ "easy to create beautiful-looking forms using Bootstrap 4"
16
+ s.license = "MIT"
17
+
18
+ s.files = `git ls-files -z`.split("\x0").reject do |f|
19
+ f.match(%r{^(test)/})
20
+ end
21
+
22
+ s.bindir = "exe"
23
+ s.require_paths = ["lib"]
24
+
25
+ s.add_dependency "rails", "~> 4.0"
26
+ end
data/demo/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # DEMO APP (Rails 5.2)
2
+
3
+ ### Usage
4
+
5
+ - `rake db:schema:load`
6
+ - `rails s`
7
+ - Navigate to http://localhost:3000
8
+
9
+ ### Following files were added or changed:
10
+
11
+ - db/schema.rb
12
+ - config/{application, routes, boot}.rb
13
+ - config/environments/{development, test}.rb
14
+ - app/models/{address,user,super_user,faux_user}.rb
15
+ - app/controllers/bootstrap_controller.rb
16
+ - app/views/layouts/application.html.erb
17
+ - app/views/bootstrap/form.html.erb
data/demo/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require_relative 'config/application'
5
+
6
+ Rails.application.load_tasks
@@ -0,0 +1,2 @@
1
+ class ApplicationController < ActionController::Base
2
+ end
@@ -0,0 +1,16 @@
1
+ class BootstrapController < ApplicationController
2
+
3
+ def form
4
+ @collection = [
5
+ Address.new(id: 1, street: 'Foo'),
6
+ Address.new(id: 2, street: 'Bar')
7
+ ]
8
+
9
+ @user = User.new
10
+
11
+ @user_with_error = User.new
12
+ @user_with_error.errors.add(:email)
13
+ @user_with_error.errors.add(:misc)
14
+ end
15
+
16
+ end
@@ -0,0 +1,23 @@
1
+ module BootstrapHelper
2
+
3
+ def form_with_source(&block)
4
+ form_html = capture(&block)
5
+
6
+ content_tag(:div, class: "example") do
7
+ codemirror = content_tag(:div, class: "code", style: "display: none") do
8
+ content_tag(:textarea, class: "codemirror") do
9
+ HtmlBeautifier.beautify(form_html.strip.gsub(">", ">\n").gsub("<", "\n<"))
10
+ end
11
+ end
12
+
13
+ toggle = content_tag(:button, class: "toggle btn btn-sm btn-info") do
14
+ "Show Source Code"
15
+ end
16
+
17
+ concat(form_html)
18
+ concat(toggle)
19
+ concat(codemirror)
20
+ end
21
+ end
22
+
23
+ end
@@ -0,0 +1,3 @@
1
+ class Address < ActiveRecord::Base
2
+ belongs_to :user
3
+ end
@@ -0,0 +1,3 @@
1
+ class ApplicationRecord < ActiveRecord::Base
2
+ self.abstract_class = true
3
+ end
@@ -0,0 +1,9 @@
1
+ class FauxUser
2
+ attr_accessor :email, :password, :comments, :misc
3
+
4
+ def initialize(attributes = {})
5
+ attributes.each do |name, value|
6
+ send("#{name}=", value)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,2 @@
1
+ class SuperUser < User
2
+ end
@@ -0,0 +1,9 @@
1
+ class User < ActiveRecord::Base
2
+ serialize :preferences
3
+
4
+ validates :email, presence: true, :length => { minimum: 5 }
5
+ validates :terms, acceptance: { accept: true }
6
+
7
+ has_one :address
8
+ accepts_nested_attributes_for :address
9
+ end
@@ -0,0 +1,53 @@
1
+ <h3>Horizontal Form</h3>
2
+
3
+ <%= form_with_source do %>
4
+ <%= bootstrap_form_for @user, layout: :horizontal do |form| %>
5
+ <%= form.email_field :email, placeholder: "Enter Email", label: "Email address", help: "We'll never share your email with anyone else" %>
6
+ <%= form.password_field :password, placeholder: "Password" %>
7
+ <%= form.select :status, [['activated', 1], ['blocked', 2]], prompt: "Please Select" %>
8
+ <%= form.text_area :misc %>
9
+ <%= form.check_box :terms, label: "Agree to Terms" %>
10
+ <%= form.collection_check_boxes :misc, @collection, :id, :street %>
11
+ <%= form.collection_radio_buttons :misc, @collection, :id, :street %>
12
+ <%= form.file_field :misc %>
13
+ <%= form.datetime_select :misc, include_blank: true %>
14
+
15
+ <%= form.submit %>
16
+ <% end %>
17
+ <% end %>
18
+
19
+ <h3>With Validation Error</h3>
20
+
21
+ <%= form_with_source do %>
22
+ <%= bootstrap_form_for @user_with_error, layout: :horizontal do |form| %>
23
+ <%= form.alert_message "This is an alert" %>
24
+ <%= form.error_summary %>
25
+ <%= form.email_field :email, placeholder: "Enter Email", label: "Email address", help: "We'll never share your email with anyone else" %>
26
+ <%= form.collection_check_boxes :misc, @collection, :id, :street %>
27
+ <%= form.submit %>
28
+ <% end %>
29
+ <% end %>
30
+
31
+ <h3>Inline Form</h3>
32
+
33
+ <%= form_with_source do %>
34
+ <%= bootstrap_form_for @user, layout: :inline do |form| %>
35
+ <%= form.email_field :email, placeholder: "Enter Email", label: "Email address", help: "We'll never share your email with anyone else" %>
36
+ <%= form.password_field :password, placeholder: "Password" %>
37
+ <%= form.check_box :terms, label: "Agree to Terms" %>
38
+ <%= form.collection_check_boxes :misc, @collection, :id, :street %>
39
+ <%= form.submit %>
40
+ <% end %>
41
+ <% end %>
42
+
43
+ <h3>Simple</h3>
44
+
45
+ <%= form_with_source do %>
46
+ <%= bootstrap_form_for @user, url: "/" do |form| %>
47
+ <%= form.email_field :email, placeholder: "Enter Email", label: "Email address", help: "We'll never share your email with anyone else" %>
48
+ <%= form.password_field :password, placeholder: "Password" %>
49
+ <%= form.check_box :terms, label: "Agree to Terms" %>
50
+ <%= form.collection_check_boxes :misc, @collection, :id, :street %>
51
+ <%= form.submit %>
52
+ <% end %>
53
+ <% end %>
@@ -0,0 +1,65 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <!-- Required meta tags -->
5
+ <meta charset="utf-8">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
7
+
8
+ <!-- Bootstrap CSS -->
9
+ <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
10
+
11
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.33.0/codemirror.min.css">
12
+
13
+ <style type="text/css">
14
+ .example {
15
+ padding: 1.5em;
16
+ border: .2rem solid #f7f7f9;
17
+ margin-bottom: 3em;
18
+ }
19
+ form {
20
+ margin-bottom: 1.5em;
21
+ }
22
+ .CodeMirror {
23
+ border: 1px solid #eee;
24
+ height: auto;
25
+ }
26
+ .rails-bootstrap-forms-datetime-select select {
27
+ display: inline-block;
28
+ width: auto;
29
+ }
30
+ </style>
31
+
32
+ <title>Hello, world!</title>
33
+ <%= csrf_meta_tags %>
34
+ </head>
35
+
36
+ <body>
37
+ <div class="container">
38
+ <%= yield %>
39
+ </div>
40
+
41
+ <!-- Optional JavaScript -->
42
+ <!-- jQuery first, then Popper.js, then Bootstrap JS -->
43
+ <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
44
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
45
+ <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
46
+
47
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.33.0/codemirror.min.js"></script>
48
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.33.0/mode/htmlmixed/htmlmixed.min.js"></script>
49
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.33.0/mode/xml/xml.min.js"></script>
50
+
51
+ <script type="text/javascript">
52
+ $(document).on("click", "button.toggle", function(){
53
+ var example = $(this).parent(".example");
54
+ $(this).hide();
55
+ $(".code", example).show()
56
+ CodeMirror.fromTextArea($("textarea.codemirror", example)[0], {
57
+ mode: "htmlmixed",
58
+ tabSize: 2,
59
+ lineNumbers: true,
60
+ viewportMargin: Infinity
61
+ })
62
+ });
63
+ </script>
64
+ </body>
65
+ </html>
data/demo/bin/bundle ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
3
+ load Gem.bin_path('bundler', 'bundle')
data/demo/bin/rails ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path('../config/application', __dir__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
data/demo/bin/rake ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../config/boot'
3
+ require 'rake'
4
+ Rake.application.run
data/demo/bin/setup ADDED
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+ require 'fileutils'
3
+ include FileUtils
4
+
5
+ # path to your application root.
6
+ APP_ROOT = File.expand_path('..', __dir__)
7
+
8
+ def system!(*args)
9
+ system(*args) || abort("\n== Command #{args} failed ==")
10
+ end
11
+
12
+ chdir APP_ROOT do
13
+ # This script is a starting point to setup your application.
14
+ # Add necessary setup steps to this file.
15
+
16
+ puts '== Installing dependencies =='
17
+ system! 'gem install bundler --conservative'
18
+ system('bundle check') || system!('bundle install')
19
+
20
+ # Install JavaScript dependencies if using Yarn
21
+ # system('bin/yarn')
22
+
23
+ # puts "\n== Copying sample files =="
24
+ # unless File.exist?('config/database.yml')
25
+ # cp 'config/database.yml.sample', 'config/database.yml'
26
+ # end
27
+
28
+ puts "\n== Preparing database =="
29
+ system! 'bin/rails db:setup'
30
+
31
+ puts "\n== Removing old logs and tempfiles =="
32
+ system! 'bin/rails log:clear tmp:clear'
33
+
34
+ puts "\n== Restarting application server =="
35
+ system! 'bin/rails restart'
36
+ end
data/demo/bin/update ADDED
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+ require 'fileutils'
3
+ include FileUtils
4
+
5
+ # path to your application root.
6
+ APP_ROOT = File.expand_path('..', __dir__)
7
+
8
+ def system!(*args)
9
+ system(*args) || abort("\n== Command #{args} failed ==")
10
+ end
11
+
12
+ chdir APP_ROOT do
13
+ # This script is a way to update your development environment automatically.
14
+ # Add necessary update steps to this file.
15
+
16
+ puts '== Installing dependencies =='
17
+ system! 'gem install bundler --conservative'
18
+ system('bundle check') || system!('bundle install')
19
+
20
+ # Install JavaScript dependencies if using Yarn
21
+ # system('bin/yarn')
22
+
23
+ puts "\n== Updating database =="
24
+ system! 'bin/rails db:migrate'
25
+
26
+ puts "\n== Removing old logs and tempfiles =="
27
+ system! 'bin/rails log:clear tmp:clear'
28
+
29
+ puts "\n== Restarting application server =="
30
+ system! 'bin/rails restart'
31
+ end
data/demo/bin/yarn ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path('..', __dir__)
3
+ Dir.chdir(APP_ROOT) do
4
+ begin
5
+ exec "yarnpkg #{ARGV.join(' ')}"
6
+ rescue Errno::ENOENT
7
+ $stderr.puts "Yarn executable was not detected in the system."
8
+ $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"
9
+ exit 1
10
+ end
11
+ end
data/demo/config.ru ADDED
@@ -0,0 +1,5 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require_relative 'config/environment'
4
+
5
+ run Rails.application
@@ -0,0 +1,24 @@
1
+ require_relative 'boot'
2
+
3
+ require 'rails/all'
4
+
5
+ Bundler.require(*Rails.groups)
6
+ require "bootstrap_form"
7
+
8
+ module Dummy
9
+ class Application < Rails::Application
10
+ # Initialize configuration defaults for originally generated Rails version.
11
+
12
+ if config.respond_to?(:load_defaults)
13
+ config.load_defaults [Rails::VERSION::MAJOR, Rails::VERSION::MINOR].join(".")
14
+ end
15
+
16
+ if config.respond_to?(:secret_key_base)
17
+ config.secret_key_base = "ignore"
18
+ end
19
+
20
+ # Settings in config/environments/* take precedence over those specified here.
21
+ # Application configuration should go into files in config/initializers
22
+ # -- all .rb files in that directory are automatically loaded.
23
+ end
24
+ end
@@ -0,0 +1,5 @@
1
+ # Set up gems listed in the Gemfile.
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __dir__)
3
+
4
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
5
+ $LOAD_PATH.unshift File.expand_path('../../lib', __dir__)
@@ -0,0 +1,21 @@
1
+ # SQLite version 3.x
2
+ # gem install sqlite3
3
+ #
4
+ # Ensure the SQLite 3 gem is defined in your Gemfile
5
+ # gem 'sqlite3'
6
+ #
7
+ default: &default
8
+ adapter: sqlite3
9
+ pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
10
+ timeout: 5000
11
+
12
+ development:
13
+ <<: *default
14
+ database: db/development.sqlite3
15
+
16
+ # Warning: The database defined as "test" will be erased and
17
+ # re-generated from your development database when you run "rake".
18
+ # Do not set this db to the same as development or production.
19
+ test:
20
+ <<: *default
21
+ database: db/test.sqlite3