voncount 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.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +52 -0
- data/Rakefile +1 -0
- data/lib/voncount/railtie.rb +10 -0
- data/lib/voncount/version.rb +3 -0
- data/lib/voncount/voncount_form_helpers.rb +67 -0
- data/lib/voncount.rb +7 -0
- data/vendor/assets/javascripts/vonCount.js +29 -0
- data/vendor/assets/stylesheets/vonCount.css +3 -0
- data/voncount.gemspec +24 -0
- metadata +106 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Simon Jones
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# Von Count
|
2
|
+
|
3
|
+
Count characters with Von Count
|
4
|
+
|
5
|
+
A simple twitter-style character counter gem that includes form helpers for easy use.
|
6
|
+
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add the following to your Gemfile
|
11
|
+
|
12
|
+
gem 'voncount'
|
13
|
+
|
14
|
+
Add the following directive to your Javascript manifest file (application.js):
|
15
|
+
|
16
|
+
//= require voncount
|
17
|
+
|
18
|
+
Add the following to your Stylesheet manifest file (application.cs):
|
19
|
+
|
20
|
+
*= require voncount
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
To include a character counter on a text field use whichever of the following you need:
|
25
|
+
|
26
|
+
= f.voncount_text_field :field_name, maxlength: 120
|
27
|
+
|
28
|
+
or
|
29
|
+
|
30
|
+
= voncount_text_field_tag "field_name", "Value", maxlength: 120
|
31
|
+
|
32
|
+
or
|
33
|
+
|
34
|
+
= voncount_text_field "object_name", "field_name", maxlength: 120
|
35
|
+
|
36
|
+
|
37
|
+
To include a character counter on a text area use whichever of the following you need:
|
38
|
+
|
39
|
+
= f.voncount_text_area :field_name, maxlength: 120
|
40
|
+
|
41
|
+
or
|
42
|
+
|
43
|
+
= voncount_text_area_tag "field_name", "Value", maxlength: 120
|
44
|
+
|
45
|
+
or
|
46
|
+
|
47
|
+
= voncount_text_area "object_name", "field_name", maxlength: 120
|
48
|
+
|
49
|
+
|
50
|
+
Default max character length is 255, this value is overridden by the maxlength option applied to the field
|
51
|
+
|
52
|
+

|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'voncount/voncount_form_helpers'
|
2
|
+
module Voncount
|
3
|
+
class Railtie < Rails::Railtie
|
4
|
+
initializer "voncount.voncount_form_helpers" do |app|
|
5
|
+
ActionView::Base.send :include, FormTagHelperExt
|
6
|
+
ActionView::Base.send :include, FormHelperExt
|
7
|
+
ActionView::Helpers::FormBuilder.send :include, FormBuilderExt
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module Voncount
|
2
|
+
module FormTagHelperExt
|
3
|
+
def voncount_text_field_tag(name, value = nil, options = {})
|
4
|
+
options[:class] = "von-countable #{options[:class]}"
|
5
|
+
content_tag :div, class: "von-count-holder" do
|
6
|
+
tag(:input, { "type" => "text", "name" => name, "id" => sanitize_to_id(name), "value" => value }.update(options.stringify_keys)) +
|
7
|
+
content_tag(:span, '0', class: "von-counter")
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def voncount_text_area_tag(name, content = nil, options = {})
|
12
|
+
options[:class] = "von-countable #{options[:class]}"
|
13
|
+
options = options.stringify_keys
|
14
|
+
|
15
|
+
if size = options.delete("size")
|
16
|
+
options["cols"], options["rows"] = size.split("x") if size.respond_to?(:split)
|
17
|
+
end
|
18
|
+
|
19
|
+
escape = options.delete("escape") { true }
|
20
|
+
content = ERB::Util.html_escape(content) if escape
|
21
|
+
|
22
|
+
options[:class] = "von-countable #{options[:class]}"
|
23
|
+
content_tag :div, class: "von-count-holder" do
|
24
|
+
content_tag(:textarea, content.to_s.html_safe, { "name" => name, "id" => sanitize_to_id(name) }.update(options)) +
|
25
|
+
content_tag(:span, '0', class: "von-counter")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
module FormHelperExt
|
31
|
+
def voncount_text_field(object_name, method, options = {})
|
32
|
+
options[:class] = "von-countable #{options[:class]}"
|
33
|
+
content_tag :div, class: "von-count-holder" do
|
34
|
+
ActionView::Helpers::Tags::TextField.new(object_name, method, self, options).render +
|
35
|
+
content_tag(:span, '0', class: "von-counter")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def voncount_text_area(object_name, method, options = {})
|
40
|
+
options[:class] = "von-countable #{options[:class]}"
|
41
|
+
content_tag :div, class: "von-count-holder" do
|
42
|
+
ActionView::Helpers::Tags::TextArea.new(object_name, method, self, options).render +
|
43
|
+
content_tag(:span, '0', class: "von-counter")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
module FormBuilderExt
|
49
|
+
include ActionView::Context
|
50
|
+
include ActionView::Helpers::TagHelper
|
51
|
+
def voncount_text_field(method, options = {})
|
52
|
+
options[:class] = "von-countable #{options[:class]}"
|
53
|
+
content_tag :div, class: "von-count-holder" do
|
54
|
+
@template.send("text_field", @object_name, method, objectify_options(options)) +
|
55
|
+
content_tag(:span, '0', class: "von-counter")
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def voncount_text_area(method, options = {})
|
60
|
+
options[:class] = "von-countable #{options[:class]}"
|
61
|
+
content_tag :div, class: "von-count-holder" do
|
62
|
+
@template.send("text_area", @object_name, method, objectify_options(options)) +
|
63
|
+
content_tag(:span, '0', class: "von-counter")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/lib/voncount.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
(function($) {
|
2
|
+
var initCounter;
|
3
|
+
|
4
|
+
initCounter = function($field, $counter) {
|
5
|
+
var countCharacters, maxLength;
|
6
|
+
maxLength = $field.attr('maxlength') || 255;
|
7
|
+
countCharacters = function() {
|
8
|
+
var len, value;
|
9
|
+
value = $field.val();
|
10
|
+
len = value.length;
|
11
|
+
if (len >= maxLength) {
|
12
|
+
$field.value = value.substring(0, maxLength);
|
13
|
+
}
|
14
|
+
return $counter.text(maxLength - len);
|
15
|
+
};
|
16
|
+
$field.on('keydown keyup change blur focus', function() {
|
17
|
+
return countCharacters();
|
18
|
+
});
|
19
|
+
countCharacters()
|
20
|
+
};
|
21
|
+
|
22
|
+
setTimeout(function(){
|
23
|
+
$('.von-countable').each(function() {
|
24
|
+
var $field;
|
25
|
+
$field = $(this);
|
26
|
+
initCounter($field, $field.nextAll('.von-counter'));
|
27
|
+
});
|
28
|
+
}, 300);
|
29
|
+
})(jQuery);
|
data/voncount.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'voncount/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "voncount"
|
8
|
+
spec.version = Voncount::VERSION
|
9
|
+
spec.authors = ["Simon Jones"]
|
10
|
+
spec.email = ["spj3rd@googlemail.com"]
|
11
|
+
spec.description = "Count characters like The Count"
|
12
|
+
spec.summary = "Simple js-rails character counter."
|
13
|
+
spec.homepage = "http://simonjones.github.io/voncount"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_dependency "railties"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: voncount
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Simon Jones
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-08-18 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: railties
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: Count characters like The Count
|
63
|
+
email:
|
64
|
+
- spj3rd@googlemail.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- Gemfile
|
71
|
+
- LICENSE.txt
|
72
|
+
- README.md
|
73
|
+
- Rakefile
|
74
|
+
- lib/voncount.rb
|
75
|
+
- lib/voncount/railtie.rb
|
76
|
+
- lib/voncount/version.rb
|
77
|
+
- lib/voncount/voncount_form_helpers.rb
|
78
|
+
- vendor/assets/javascripts/vonCount.js
|
79
|
+
- vendor/assets/stylesheets/vonCount.css
|
80
|
+
- voncount.gemspec
|
81
|
+
homepage: http://simonjones.github.io/voncount
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ! '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
requirements: []
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 1.8.24
|
103
|
+
signing_key:
|
104
|
+
specification_version: 3
|
105
|
+
summary: Simple js-rails character counter.
|
106
|
+
test_files: []
|