initial import

This commit is contained in:
John Bintz 2012-10-23 08:26:14 -04:00
commit 2a180fa433
10 changed files with 173 additions and 0 deletions

17
.gitignore vendored Normal file
View File

@ -0,0 +1,17 @@
*.gem
*.rbc
.bundle
.config
.yardoc
Gemfile.lock
InstalledFiles
_yardoc
coverage
doc/
lib/bundler/man
pkg
rdoc
spec/reports
test/tmp
test/version_tmp
tmp

4
Gemfile Normal file
View File

@ -0,0 +1,4 @@
source 'https://rubygems.org'
# Specify your gem's dependencies in formtastic-separate_html5_date_and_time.gemspec
gemspec

22
LICENSE.txt Normal file
View File

@ -0,0 +1,22 @@
Copyright (c) 2012 John Bintz
MIT License
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

29
README.md Normal file
View File

@ -0,0 +1,29 @@
# Formtastic::SeparateHtml5DateAndTime
TODO: Write a gem description
## Installation
Add this line to your application's Gemfile:
gem 'formtastic-separate_html5_date_and_time'
And then execute:
$ bundle
Or install it yourself as:
$ gem install formtastic-separate_html5_date_and_time
## Usage
TODO: Write usage instructions here
## Contributing
1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request

1
Rakefile Normal file
View File

@ -0,0 +1 @@
require "bundler/gem_tasks"

View File

@ -0,0 +1,19 @@
# -*- encoding: utf-8 -*-
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'formtastic-separate_html5_date_and_time/version'
Gem::Specification.new do |gem|
gem.name = "formtastic-separate_html5_date_and_time"
gem.version = Formtastic::SeparateHtml5DateAndTime::VERSION
gem.authors = ["John Bintz"]
gem.email = ["john@coswellproductions.com"]
gem.description = %q{Separate HTML 5 date and time fields for use with existing polyfills and Mongoid}
gem.summary = %q{Separate HTML 5 date and time fields for use with existing polyfills and Mongoid}
gem.homepage = ""
gem.files = `git ls-files`.split($/)
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
gem.require_paths = ["lib"]
end

View File

@ -0,0 +1,17 @@
require "formtastic-separate_html5_date_and_time/version"
module Formtastic
module SeparateHtml5DateAndTime
class Railtie < ::Rails::Railtie
initializer 'separate_html5_date_and_time.initialize' do
require 'formtastic'
require 'formtastic-separate_html5_date_and_time/formtastic'
if defined?(Mongoid::Document)
require 'formtastic-separate_html5_date_and_time/mongoid'
end
end
end
end
end

View File

@ -0,0 +1,31 @@
class SeparateDateAndTimePickerInput < Formtastic::Inputs::DatetimePickerInput
def to_html
input_wrapping do
label_html <<
builder.text_field("#{method}(date)", date_input_html_options) <<
builder.text_field("#{method}(time)", time_input_html_options)
end
end
def date_input_html_options
{ 'type' => 'date', 'value' => date_value }
end
def time_input_html_options
{ 'type' => 'time', 'value' => time_value }
end
def date_value
value_parts.first
end
def time_value
value_parts.last
end
def value_parts
@value_parts ||= (value || '').split(' ')
end
end

View File

@ -0,0 +1,28 @@
require 'mongoid'
module Mongoid
module ProcessSeparateDateAndTimePickerInputs
def process_attributes(attrs = nil, role = :default, guard_protected_attributes = true)
if attrs
datetime_attrs = {}
attrs.each do |key, value|
if attr = key[/\A(.*)\((date|time)\)\Z/, 1]
datetime_attrs[attr] ||= {}
datetime_attrs[attr][key] = value
end
end
datetime_attrs.each do |attr, values|
attrs[attr] = values["#{attr}(date)"] + ' ' + values["#{attr}(time)"]
attrs.delete("#{attr}(date)")
attrs.delete("#{attr}(time)")
end
end
super(attrs, role, guard_protected_attributes)
end
end
end

View File

@ -0,0 +1,5 @@
module Formtastic
module SeparateHtml5DateAndTime
VERSION = "0.0.1"
end
end