form_input 0.9.0.pre1 → 0.9.0.pre2

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: 678c61eba81b4b64a00bb350459c067867e1bddc
4
- data.tar.gz: c778e133cf9afc68e3799f1d86bbb51d0f294ced
3
+ metadata.gz: 3ddb2e82dd3950263088d75c48e14abda401c0b6
4
+ data.tar.gz: 1ac5450c7a5fd75dba03ff109801c936dc35f9ea
5
5
  SHA512:
6
- metadata.gz: 869482012d35a0bd5fa6e47aee369be5a9fa8f4eae4c1a149e504ede786849ed9ae9b98e1f185ef244ad57eb8edc7ec7c625f78eab1fa8deefc1fb47bf1f9093
7
- data.tar.gz: 3aa323b2ab184e3796c9392f412b955a9e423672e2e88713fd87d9c521a1283dac514c2ef259321c571e3534da355afb7e61a8e499dafc6b05e396eea23724c6
6
+ metadata.gz: e6ea10d32dca8dad8237cb7a25e74b4dc0d4916a93668ae3504f81b85d0f67fb689553314914e8097dc891703e47908f49e999a1251803ca960a4e8c117e4ab1
7
+ data.tar.gz: a485d6797a5cff27a6a9a900b5340f2abc4a27c27b8f4b0e6a85dcdf2a118972bd907e0d21d9213bd3c10348976cb02b8475cbef1331f555e6e304abc81c53d9
data/.travis.gemfile ADDED
@@ -0,0 +1,15 @@
1
+ # Gemfile for TravisCI integration.
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gem 'rake'
6
+ gem 'rack', '~> 1.5'
7
+ gem 'rack-test'
8
+ gem 'bacon', '~> 1.2'
9
+ gem 'r18n-core', '~> 2.0'
10
+
11
+ if ENV[ 'CODECLIMATE_REPO_TOKEN' ]
12
+ gem 'codeclimate-test-reporter'
13
+ end
14
+
15
+ # EOF #
data/.travis.yml ADDED
@@ -0,0 +1,23 @@
1
+ # TravisCI config.
2
+
3
+ language: ruby
4
+ rvm:
5
+ - ruby-head
6
+ - 2.3.1
7
+ - 2.2.5
8
+ - 2.1.10
9
+ - 2.0.0
10
+ - rbx-2
11
+ - jruby-head
12
+ gemfile: .travis.gemfile
13
+ env:
14
+ global:
15
+ # travis encrypt -r raxoft/form_input CODECLIMATE_REPO_TOKEN=???
16
+ secure: "OGkm2MO8oBOsE6qQ95gca6z3pi8m5UN6vtoD+hlvR6dJpj6n4nlfWOsKq0MJWC5j1260p6EQCfKkfXA0s/rtYbdHpgb4Qhtm9/wKwwyOItyMMdXfaazNhKhLRLnib9RSSxXxjpZY40Lcsb3HWjZbjeIEgu03gn8RtXkmJFG4gqxnpmzw4Xloq8AWl0tO3ItP07VGhbJjCEftweGlICiNZ9XQPq87Bnqr5D9NqBkHAUJm9SpG15y9Dt9by3OPq/PXnh/juXybP7V2IMGhFu1WudLVDy2Bd1VQVbFb7uk51Mko8esDFr5WK0E675CJ2CCm8AaoA+Uwk5cpSB2HCbZ80OSE+Jl60F8NqBfxMvpw/pY0xb/tdGLnXAureU9eWted3XTwtZoq+k/7TdirFCU5u48VxszrJs96QoVi2rh1iPwBXZmGO4aEfkCT/wmqL0Tbi0s69XjjjtNINvXwynXmYG3PbPKG0iDKIJAvwdh+KmBLLd+cKeZp5jJ5npgmsWRcgMm2HHGskb8etv4AFSVvHA8PDQR7E/GalKhSZclUjLlOq+qhGklCi/Mhy8XlAIn+yIXzL3Rlw/bWL56iC/PHzi5vNC4ia8PwlPB+FqOS5T5vwtj4NcDc+6k6yTWRNZZ9cEBeS2xO0TOAFe3qE//PkztW7tJ0Qlgc0aS9Q2+uH9Y="
17
+ matrix:
18
+ allow_failures:
19
+ - rvm: rbx-2
20
+ - rvm: ruby-head
21
+ - rvm: jruby-head
22
+
23
+ # EOF #
data/.yardopts ADDED
@@ -0,0 +1,3 @@
1
+ --markup-provider redcarpet
2
+ --markup markdown
3
+ - README.md LICENSE
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # Form input
2
2
 
3
- Form input is a gem which helps dealing with a web request input and with the creation of HTML forms.
3
+ [![Gem Version](https://img.shields.io/gem/v/form_input.svg)](http://rubygems.org/gems/form_input) [![Build Status](https://travis-ci.org/raxoft/form_input.svg?branch=master)](http://travis-ci.org/raxoft/form_input) [![Dependency Status](https://img.shields.io/gemnasium/raxoft/form_input.svg)](https://gemnasium.com/raxoft/form_input) [![Code Climate](https://img.shields.io/codeclimate/github/raxoft/form_input.svg)](https://codeclimate.com/github/raxoft/form_input) [![Coverage](https://img.shields.io/codeclimate/coverage/github/raxoft/form_input.svg)](https://codeclimate.com/github/raxoft/form_input)
4
+
5
+ Form input is a gem which helps dealing with web request input and with the creation of HTML forms.
4
6
 
5
7
  Install the gem:
6
8
 
@@ -3140,6 +3142,11 @@ Thanks for that.
3140
3142
 
3141
3143
  Copyright © 2015-2016 Patrik Rak
3142
3144
 
3145
+ Translations contributed by
3146
+ Maroš Rovňák (Slovak)
3147
+ and
3148
+ Eryk Dwornicki (Polish).
3149
+
3143
3150
  The `FormInput` is released under the MIT license.
3144
3151
 
3145
3152
 
data/form_input.gemspec CHANGED
@@ -4,7 +4,7 @@ require File.expand_path( '../lib/form_input/version', __FILE__ )
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = 'form_input'
7
- s.version = FormInput::Version::STRING + '.pre1'
7
+ s.version = FormInput::Version::STRING + '.pre2'
8
8
  s.summary = 'Form helper which sanitizes, transforms, validates and encapsulates web request input.'
9
9
  s.description = <<EOT
10
10
  This gem allows you to describe your forms using a simple DSL
@@ -26,6 +26,7 @@ EOT
26
26
  s.required_ruby_version = '>= 2.0.0'
27
27
  s.add_runtime_dependency 'rack', '~> 1.5'
28
28
  s.add_development_dependency 'bacon', '~> 1.2'
29
+ s.add_development_dependency 'rack-test', '~> 0.6'
29
30
  s.add_development_dependency 'r18n-core', '~> 2.0'
30
31
  end
31
32
 
@@ -7,7 +7,7 @@ require 'form_input/r18n'
7
7
  class Hash
8
8
  # Convert all hash keys to strings recursively.
9
9
  def stringify_keys
10
- map{ |k, v| [ k.to_s, v.respond_to?( :stringify_keys ) ? v.stringify_keys : v ] }.to_h
10
+ Hash[ map{ |k, v| [ k.to_s, v.respond_to?( :stringify_keys ) ? v.stringify_keys : v ] } ]
11
11
  end
12
12
  end
13
13
 
@@ -23,25 +23,25 @@ class FormInput
23
23
 
24
24
  # Get hash of all parameter values which may need to be localized.
25
25
  def translation_hash
26
- opts.select{ |k, v| v.is_a? String }.sort_by{ |k, v| [ translation_order( k ), k ] }.to_h
26
+ Hash[ opts.select{ |k, v| v.is_a? String }.sort_by{ |k, v| [ translation_order( k ), k ] } ]
27
27
  end
28
28
  end
29
29
 
30
30
  # Get hash of all form values which may need to be localized.
31
31
  def self.translation_hash
32
- hash = form_params.map{ |k, v| [ k, v.translation_hash ] }.reject{ |k, v| v.empty? }.to_h
32
+ hash = Hash[ form_params.map{ |k, v| [ k, v.translation_hash ] }.reject{ |k, v| v.empty? } ]
33
33
  hash[ :steps ] = form_steps.reject{ |k, v| v.nil? } if form_steps
34
34
  hash
35
35
  end
36
36
 
37
37
  # Get list of all classes inherited from FormInput.
38
38
  def self.forms
39
- ObjectSpace.each_object( Class ).select{ |x| x < FormInput }
39
+ ObjectSpace.each_object( Class ).select{ |x| x < FormInput and x.name }.sort_by{ |x| x.name }
40
40
  end
41
41
 
42
- # Get string containing YAML representation of the default R18n translation for current project.
43
- def self.default_translation
44
- hash = forms.sort_by{ |x| x.name }.map{ |x| [ x.translation_name, x.translation_hash ] }.reject{ |k, v| v.empty? }.to_h
42
+ # Get string containing YAML representation of the default R18n translation for all/given FormInput classes.
43
+ def self.default_translation(forms = self.forms)
44
+ hash = Hash[ forms.map{ |x| [ x.translation_name, x.translation_hash ] }.reject{ |k, v| v.empty? } ]
45
45
  YAML::dump( { forms: hash }.stringify_keys )
46
46
  end
47
47
  end
data/test/localize/en.yml CHANGED
@@ -1,63 +1,24 @@
1
1
  ---
2
2
  forms:
3
- test_form:
4
- email:
5
- title: Email
6
- form_title: Your email
7
- error_title: email address
8
- password:
9
- title: Password
10
- msg: Password must contain one lowercase and one uppercase letter and one digit
11
- test_inflection_form:
12
- name:
13
- title: Name
14
- address:
15
- title: Address
16
- state:
17
- title: State
18
- author:
19
- title: Author
20
- friends:
21
- title: Friends
22
- chars:
23
- title: Characters
24
- keywords:
25
- title: Keywords
26
- notes:
27
- title: Notes
28
3
  test_localize_form:
29
4
  simple:
30
5
  title: String
6
+ complex:
7
+ title: Title
8
+ form_title: Form Title
9
+ error_title: Error Title
10
+ required_msg: "%p is required!"
11
+ msg: "%p must contain at least one letter"
12
+ reject_msg: "%p must not contain a digit"
13
+ help: Help
14
+ placeholder: Placeholder
15
+ subtitle: Subtitle
31
16
  utf:
32
17
  title: "ěščřžýáíéúůďťň"
33
18
  yaml:
34
19
  title: "%"
35
20
  msg: "{}"
36
- test_localized_steps_form:
37
21
  steps:
38
22
  one: First
39
23
  two: Second
40
24
  three: Third
41
- test_r18n_form:
42
- msg:
43
- title: Message
44
- msg2:
45
- title: Second Message
46
- test_steps_form:
47
- steps:
48
- intro: Intro
49
- email: Email
50
- name: Name
51
- address: Address
52
- message: Message
53
- test_time_types_form:
54
- time:
55
- placeholder: YYYY-MM-DD HH:MM:SS
56
- us_date:
57
- placeholder: MM/DD/YYYY
58
- uk_date:
59
- placeholder: DD/MM/YYYY
60
- eu_date:
61
- placeholder: D.M.YYYY
62
- hours:
63
- placeholder: HH:MM
@@ -5,18 +5,42 @@ require_relative 'helper'
5
5
  require 'form_input/localize'
6
6
 
7
7
  class TestLocalizeForm < FormInput
8
+
9
+ define_steps(
10
+ one: "First",
11
+ two: "Second",
12
+ three: "Third",
13
+ four: nil,
14
+ )
8
15
  param :simple, "String"
16
+ param :complex, "Title",
17
+ subtitle: "Subtitle",
18
+ form_title: "Form Title",
19
+ error_title: "Error Title",
20
+ required_msg: "%p is required!",
21
+ match: /[a-z]/i,
22
+ msg: "%p must contain at least one letter",
23
+ reject: /\d/,
24
+ reject_msg: "%p must not contain a digit",
25
+ help: "Help",
26
+ placeholder: "Placeholder"
9
27
  param :utf, "ěščřžýáíéúůďťň"
10
28
  param :yaml, '%', msg: '{}'
29
+
11
30
  end
12
31
 
13
32
  describe FormInput do
14
33
 
34
+ should 'provide helper which returns all form classes' do
35
+ FormInput.forms.each{ |x| x.should < FormInput }
36
+ FormInput.forms.should.include TestLocalizeForm
37
+ end
38
+
15
39
  should 'provide helper to create default translation file' do
16
- text = FormInput.default_translation
40
+ text = FormInput.default_translation( [ TestLocalizeForm ] )
17
41
  name = File.expand_path( "#{__FILE__}/../localize/en.yml" )
18
42
  if File.exists?( name )
19
- text.should == File.read( name )
43
+ YAML.load( text ).should == YAML.load( File.read( name ) )
20
44
  else
21
45
  File.write( name, text )
22
46
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: form_input
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0.pre1
4
+ version: 0.9.0.pre2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrik Rak
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-20 00:00:00.000000000 Z
11
+ date: 2016-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rack-test
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.6'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: r18n-core
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +80,9 @@ extensions: []
66
80
  extra_rdoc_files: []
67
81
  files:
68
82
  - ".gitignore"
83
+ - ".travis.gemfile"
84
+ - ".travis.yml"
85
+ - ".yardopts"
69
86
  - LICENSE
70
87
  - README.md
71
88
  - Rakefile