person-name 0.2.10 → 0.2.11
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/Gemfile +3 -9
- data/Rakefile +2 -51
- data/extras/formtastic_input.rb +23 -0
- data/extras/person-name.jquery.js +148 -0
- data/lib/person_name/version.rb +5 -0
- data/person-name.gemspec +21 -0
- data/spec/spec_helper.rb +1 -1
- metadata +21 -18
- data/Gemfile.lock +0 -101
- data/VERSION +0 -1
- data/spec/database.yml +0 -17
- data/spec/person_name/has_person_name.sqlite3 +0 -0
data/.gitignore
ADDED
data/Gemfile
CHANGED
@@ -1,10 +1,4 @@
|
|
1
|
-
source
|
1
|
+
source "http://rubygems.org"
|
2
2
|
|
3
|
-
#
|
4
|
-
|
5
|
-
gem 'rspec', '2.0.1'
|
6
|
-
gem 'sqlite3-ruby', :require => 'sqlite3'
|
7
|
-
gem 'mysql'
|
8
|
-
gem 'pg'
|
9
|
-
gem 'jeweler'
|
10
|
-
gem 'rcov'
|
3
|
+
# Specify your gem's dependencies in person-name.gemspec
|
4
|
+
gemspec
|
data/Rakefile
CHANGED
@@ -1,51 +1,2 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'spec/rake/spectask'
|
4
|
-
|
5
|
-
desc 'Default: run specs'
|
6
|
-
task :default => :spec
|
7
|
-
Spec::Rake::SpecTask.new do |t|
|
8
|
-
t.spec_files = FileList["spec/**/*_spec.rb"]
|
9
|
-
end
|
10
|
-
|
11
|
-
Spec::Rake::SpecTask.new('rcov') do |t|
|
12
|
-
t.spec_files = FileList["spec/**/*_spec.rb"]
|
13
|
-
t.rcov = true
|
14
|
-
t.rcov_opts = ['--exclude', 'spec']
|
15
|
-
end
|
16
|
-
|
17
|
-
rescue LoadError
|
18
|
-
# Rspec 2.0
|
19
|
-
require 'rspec/core/rake_task'
|
20
|
-
|
21
|
-
desc 'Default: run specs'
|
22
|
-
task :default => :spec
|
23
|
-
Rspec::Core::RakeTask.new do |t|
|
24
|
-
t.pattern = "spec/**/*_spec.rb"
|
25
|
-
end
|
26
|
-
|
27
|
-
Rspec::Core::RakeTask.new('rcov') do |t|
|
28
|
-
t.pattern = "spec/**/*_spec.rb"
|
29
|
-
t.rcov = true
|
30
|
-
t.rcov_opts = ['--exclude', 'spec']
|
31
|
-
end
|
32
|
-
|
33
|
-
rescue LoadError
|
34
|
-
puts "Rspec not available. Install it with: gem install rspec"
|
35
|
-
end
|
36
|
-
|
37
|
-
begin
|
38
|
-
require 'jeweler'
|
39
|
-
Jeweler::Tasks.new do |gemspec|
|
40
|
-
gemspec.name = "person-name"
|
41
|
-
gemspec.summary = "Easy editing of person names."
|
42
|
-
gemspec.description = "Manages all person name fields (prefix, first name, middle name, intercalation, last name, suffix)"
|
43
|
-
gemspec.email = "matthijs.groen@gmail.com"
|
44
|
-
gemspec.homepage = "http://github.com/matthijsgroen/person-name"
|
45
|
-
gemspec.authors = ["Matthijs Groen"]
|
46
|
-
gemspec.files = FileList["[A-Z]*", "{generators,lib,spec,rails}/**/*"] - FileList["**/*.log"]
|
47
|
-
end
|
48
|
-
Jeweler::GemcutterTasks.new
|
49
|
-
rescue LoadError
|
50
|
-
puts "Jeweler not available. Install it with: gem install jeweler"
|
51
|
-
end
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
@@ -0,0 +1,23 @@
|
|
1
|
+
#
|
2
|
+
# Code snippet to create a formtastic input
|
3
|
+
# You can use this code in your custom formbuilder
|
4
|
+
#
|
5
|
+
# Usage: form.input :name, :as => :person_name
|
6
|
+
#
|
7
|
+
|
8
|
+
module Formtastic
|
9
|
+
module PersonName
|
10
|
+
def person_name_input(method, options)
|
11
|
+
html_options = options.delete(:input_html) || {}
|
12
|
+
html_options = default_string_options(method, :person_name).merge(html_options)
|
13
|
+
html_options[:class] = [html_options[:class], "person-name"].compact.join(" ")
|
14
|
+
|
15
|
+
part_fields = PersonName::NameSplitter::NAME_PARTS.collect do |field_part|
|
16
|
+
self.hidden_field("#{method}_#{field_part}")
|
17
|
+
end.join.html_safe
|
18
|
+
|
19
|
+
self.label(method, options_for_label(options)) <<
|
20
|
+
content_tag(:p, self.text_field(method, html_options) << part_fields, :class => "field-group")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,148 @@
|
|
1
|
+
/**
|
2
|
+
* JQuery widget for the formtastic person-name field
|
3
|
+
* This widget adds an 'expand' button to the name field to popup a dialog to edit all individual fields
|
4
|
+
*
|
5
|
+
* Usage:
|
6
|
+
* // Init person names
|
7
|
+
* $('form.formtastic input.person-name').personName({
|
8
|
+
* lookupUrl: "/people/split-name.json",
|
9
|
+
* formClass: "formtastic"
|
10
|
+
* });
|
11
|
+
*
|
12
|
+
* In the PeopleController:
|
13
|
+
*
|
14
|
+
* def split_name
|
15
|
+
* @result = PersonName::NameSplitter.split(params[:name], params[:values])
|
16
|
+
* respond_with(@result) do |format|
|
17
|
+
* format.json { render :text => @result.to_json }
|
18
|
+
* end
|
19
|
+
* end
|
20
|
+
*
|
21
|
+
*
|
22
|
+
*/
|
23
|
+
(function($, undefined) {
|
24
|
+
|
25
|
+
$.widget("ui.personName", {
|
26
|
+
options: {
|
27
|
+
lookupUrl: "",
|
28
|
+
dialogId: "person-name-detail-edit-dialog",
|
29
|
+
labels: {
|
30
|
+
prefix: "Voorvoegsel",
|
31
|
+
firstName: "Voornaam",
|
32
|
+
middleName: "Extra voornamen",
|
33
|
+
intercalation: "Tussenvoegsel",
|
34
|
+
lastName: "Achternaam",
|
35
|
+
suffix: "Achtervoegsel",
|
36
|
+
dialogButton: "Naam bewerken"
|
37
|
+
},
|
38
|
+
dialog: {
|
39
|
+
ajaxErrorMessage: "Naam informatie kon niet automatisch worden gesplitst."
|
40
|
+
},
|
41
|
+
formClass: ""
|
42
|
+
},
|
43
|
+
nameFields: ["prefix", "first_name", "middle_name", "intercalation", "last_name", "suffix"],
|
44
|
+
_create: function() {
|
45
|
+
this.element.after(" <a href=\"#edit-name\">" + this.options.labels.dialogButton + "</a>");
|
46
|
+
|
47
|
+
this.originalFieldLabel = $("label[for=" + this.element.attr("id") + "]").html();
|
48
|
+
this.element.parent().find("a:first").button({
|
49
|
+
text: false,
|
50
|
+
icons: {
|
51
|
+
primary: "ui-icon-newwin"
|
52
|
+
}
|
53
|
+
}).bind("click", this, this._editClick);
|
54
|
+
},
|
55
|
+
destroy: function() {
|
56
|
+
this.element.parent().find("a:first").unblind("click", this._editClick);
|
57
|
+
$.Widget.prototype.destroy.apply(this, arguments);
|
58
|
+
},
|
59
|
+
_editClick: function(event) {
|
60
|
+
if (event.data.options.lookupUrl != "") {
|
61
|
+
event.data._requestAndBuildDialog();
|
62
|
+
} else {
|
63
|
+
event.data._buildDialog();
|
64
|
+
}
|
65
|
+
return false;
|
66
|
+
},
|
67
|
+
_requestAndBuildDialog: function() {
|
68
|
+
var nameData = { "_method": "PUT"};
|
69
|
+
var prefix = "name";
|
70
|
+
nameData[prefix] = this.element.val();
|
71
|
+
nameData["values"] = {};
|
72
|
+
for (var index in this.nameFields) {
|
73
|
+
var fieldId = this.element.attr("id") + "_" + this.nameFields[index];
|
74
|
+
nameData.values[this.nameFields[index]] = $("#" + fieldId).val();
|
75
|
+
}
|
76
|
+
var self = this;
|
77
|
+
$.ajax({
|
78
|
+
data: nameData,
|
79
|
+
dataType: "json",
|
80
|
+
success: function(data, textStatus, XMLHttpRequest) {
|
81
|
+
for (var index in self.nameFields) {
|
82
|
+
var fieldId = self.element.attr("id") + "_" + self.nameFields[index];
|
83
|
+
$("#" + fieldId).val(data[self.nameFields[index]] || "");
|
84
|
+
}
|
85
|
+
self._buildDialog();
|
86
|
+
},
|
87
|
+
error: function() {
|
88
|
+
alert(self.options.dialog.ajaxErrorMessage);
|
89
|
+
self._buildDialog();
|
90
|
+
},
|
91
|
+
type: "GET",
|
92
|
+
url: this.options.lookupUrl
|
93
|
+
});
|
94
|
+
|
95
|
+
},
|
96
|
+
_buildDialog: function() {
|
97
|
+
var fieldIdPrefix = "edit_" + this.element.attr("id");
|
98
|
+
/**
|
99
|
+
* Mimic the html syntax from formtastic
|
100
|
+
*/
|
101
|
+
var dialogCode = "<div id=\"" + this.options.dialogId + "\">";
|
102
|
+
dialogCode += "<form class=\"" + this.options.formClass + "\"><fieldset><ol>";
|
103
|
+
for (var index in this.nameFields) {
|
104
|
+
var dialogFieldId = fieldIdPrefix + "_" + this.nameFields[index];
|
105
|
+
var fieldId = this.element.attr("id") + "_" + this.nameFields[index];
|
106
|
+
|
107
|
+
var labelName = this.nameFields[index].replace(/(\_[a-z])/g, function($1) { return $1.toUpperCase().replace('_',''); });
|
108
|
+
dialogCode += "<li><label for=\"" + dialogFieldId + "\">" + this.options.labels[labelName] + "</label>" +
|
109
|
+
"<input type=\"text\" id=\"" + dialogFieldId + "\" value=\"" + $("#" + fieldId).val() + "\">" +
|
110
|
+
"</li>";
|
111
|
+
}
|
112
|
+
dialogCode += "</ol></fieldset></form></div>";
|
113
|
+
this.element.after(dialogCode);
|
114
|
+
|
115
|
+
var self = this;
|
116
|
+
this.element.parent().find("#" + this.options.dialogId).dialog({
|
117
|
+
title: this.originalFieldLabel + " details bewerken",
|
118
|
+
buttons: {
|
119
|
+
"Opslaan en sluiten": function() {
|
120
|
+
self._storeDialog();
|
121
|
+
$(this).remove();
|
122
|
+
},
|
123
|
+
"Annuleren": function() {
|
124
|
+
$(this).dialog("close").remove();
|
125
|
+
}
|
126
|
+
},
|
127
|
+
modal: true
|
128
|
+
});
|
129
|
+
},
|
130
|
+
_storeDialog: function() {
|
131
|
+
var fieldIdPrefix = "edit_" + this.element.attr("id");
|
132
|
+
var values = [];
|
133
|
+
for (var index in this.nameFields) {
|
134
|
+
var dialogFieldId = fieldIdPrefix + "_" + this.nameFields[index];
|
135
|
+
var fieldId = this.element.attr("id") + "_" + this.nameFields[index];
|
136
|
+
var fieldValue = $("#" + dialogFieldId).val();
|
137
|
+
if (fieldValue != "") values.push(fieldValue);
|
138
|
+
$("#" + fieldId).val(fieldValue);
|
139
|
+
}
|
140
|
+
$(this.element).val(values.join(" "));
|
141
|
+
}
|
142
|
+
});
|
143
|
+
|
144
|
+
$.extend($.ui.personName, {
|
145
|
+
version: "1.0"
|
146
|
+
});
|
147
|
+
|
148
|
+
})(jQuery);
|
data/person-name.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "person_name/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "person-name"
|
7
|
+
s.version = PersonName::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Matthijs Groen"]
|
10
|
+
s.email = ["matthijs.groen@gmail.com"]
|
11
|
+
s.homepage = %q{http://github.com/matthijsgroen/person-name}
|
12
|
+
s.summary = %q{Easy editing of person names.}
|
13
|
+
s.description = %q{Manages all person name fields (prefix, first name, middle name, intercalation, last name, suffix)}
|
14
|
+
|
15
|
+
s.rubyforge_project = "person-name"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -5,7 +5,7 @@ begin
|
|
5
5
|
require "bundler"
|
6
6
|
|
7
7
|
if Gem::Version.new(Bundler::VERSION) <= Gem::Version.new("0.9.5")
|
8
|
-
raise RuntimeError, "Your bundler version is too old." +
|
8
|
+
raise RuntimeError, "Your bundler version.rb is too old." +
|
9
9
|
"Run `gem install bundler` to upgrade."
|
10
10
|
end
|
11
11
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: person-name
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 1
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 11
|
10
|
+
version: 0.2.11
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Matthijs Groen
|
@@ -15,35 +15,37 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2011-02-13 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
22
22
|
description: Manages all person name fields (prefix, first name, middle name, intercalation, last name, suffix)
|
23
|
-
email:
|
23
|
+
email:
|
24
|
+
- matthijs.groen@gmail.com
|
24
25
|
executables: []
|
25
26
|
|
26
27
|
extensions: []
|
27
28
|
|
28
|
-
extra_rdoc_files:
|
29
|
-
|
29
|
+
extra_rdoc_files: []
|
30
|
+
|
30
31
|
files:
|
32
|
+
- .gitignore
|
31
33
|
- Gemfile
|
32
|
-
- Gemfile.lock
|
33
34
|
- MIT-LICENSE
|
34
35
|
- README.markdown
|
35
36
|
- Rakefile
|
36
|
-
-
|
37
|
+
- extras/formtastic_input.rb
|
38
|
+
- extras/person-name.jquery.js
|
37
39
|
- lib/person-name.rb
|
38
40
|
- lib/person_name/has_person_name.rb
|
39
41
|
- lib/person_name/migration_support.rb
|
40
42
|
- lib/person_name/name.rb
|
41
43
|
- lib/person_name/name_splitter.rb
|
44
|
+
- lib/person_name/version.rb
|
45
|
+
- person-name.gemspec
|
42
46
|
- rails/init.rb
|
43
|
-
- spec/database.yml
|
44
47
|
- spec/database.yml.sample
|
45
48
|
- spec/models.rb
|
46
|
-
- spec/person_name/has_person_name.sqlite3
|
47
49
|
- spec/person_name/has_person_name_spec.rb
|
48
50
|
- spec/schema.rb
|
49
51
|
- spec/spec_helper.rb
|
@@ -52,8 +54,8 @@ homepage: http://github.com/matthijsgroen/person-name
|
|
52
54
|
licenses: []
|
53
55
|
|
54
56
|
post_install_message:
|
55
|
-
rdoc_options:
|
56
|
-
|
57
|
+
rdoc_options: []
|
58
|
+
|
57
59
|
require_paths:
|
58
60
|
- lib
|
59
61
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -76,13 +78,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
78
|
version: "0"
|
77
79
|
requirements: []
|
78
80
|
|
79
|
-
rubyforge_project:
|
80
|
-
rubygems_version: 1.
|
81
|
+
rubyforge_project: person-name
|
82
|
+
rubygems_version: 1.4.1
|
81
83
|
signing_key:
|
82
84
|
specification_version: 3
|
83
85
|
summary: Easy editing of person names.
|
84
86
|
test_files:
|
85
|
-
- spec/
|
86
|
-
- spec/spec_helper.rb
|
87
|
+
- spec/database.yml.sample
|
87
88
|
- spec/models.rb
|
89
|
+
- spec/person_name/has_person_name_spec.rb
|
88
90
|
- spec/schema.rb
|
91
|
+
- spec/spec_helper.rb
|
data/Gemfile.lock
DELETED
@@ -1,101 +0,0 @@
|
|
1
|
-
GEM
|
2
|
-
remote: http://rubygems.org/
|
3
|
-
specs:
|
4
|
-
abstract (1.0.0)
|
5
|
-
actionmailer (3.0.1)
|
6
|
-
actionpack (= 3.0.1)
|
7
|
-
mail (~> 2.2.5)
|
8
|
-
actionpack (3.0.1)
|
9
|
-
activemodel (= 3.0.1)
|
10
|
-
activesupport (= 3.0.1)
|
11
|
-
builder (~> 2.1.2)
|
12
|
-
erubis (~> 2.6.6)
|
13
|
-
i18n (~> 0.4.1)
|
14
|
-
rack (~> 1.2.1)
|
15
|
-
rack-mount (~> 0.6.12)
|
16
|
-
rack-test (~> 0.5.4)
|
17
|
-
tzinfo (~> 0.3.23)
|
18
|
-
activemodel (3.0.1)
|
19
|
-
activesupport (= 3.0.1)
|
20
|
-
builder (~> 2.1.2)
|
21
|
-
i18n (~> 0.4.1)
|
22
|
-
activerecord (3.0.1)
|
23
|
-
activemodel (= 3.0.1)
|
24
|
-
activesupport (= 3.0.1)
|
25
|
-
arel (~> 1.0.0)
|
26
|
-
tzinfo (~> 0.3.23)
|
27
|
-
activeresource (3.0.1)
|
28
|
-
activemodel (= 3.0.1)
|
29
|
-
activesupport (= 3.0.1)
|
30
|
-
activesupport (3.0.1)
|
31
|
-
arel (1.0.1)
|
32
|
-
activesupport (~> 3.0.0)
|
33
|
-
builder (2.1.2)
|
34
|
-
diff-lcs (1.1.2)
|
35
|
-
erubis (2.6.6)
|
36
|
-
abstract (>= 1.0.0)
|
37
|
-
gemcutter (0.6.1)
|
38
|
-
git (1.2.5)
|
39
|
-
i18n (0.4.1)
|
40
|
-
jeweler (1.4.0)
|
41
|
-
gemcutter (>= 0.1.0)
|
42
|
-
git (>= 1.2.5)
|
43
|
-
rubyforge (>= 2.0.0)
|
44
|
-
json_pure (1.4.6)
|
45
|
-
mail (2.2.7)
|
46
|
-
activesupport (>= 2.3.6)
|
47
|
-
mime-types
|
48
|
-
treetop (>= 1.4.5)
|
49
|
-
mime-types (1.16)
|
50
|
-
mysql (2.8.1)
|
51
|
-
pg (0.9.0)
|
52
|
-
polyglot (0.3.1)
|
53
|
-
rack (1.2.1)
|
54
|
-
rack-mount (0.6.13)
|
55
|
-
rack (>= 1.0.0)
|
56
|
-
rack-test (0.5.6)
|
57
|
-
rack (>= 1.0)
|
58
|
-
rails (3.0.1)
|
59
|
-
actionmailer (= 3.0.1)
|
60
|
-
actionpack (= 3.0.1)
|
61
|
-
activerecord (= 3.0.1)
|
62
|
-
activeresource (= 3.0.1)
|
63
|
-
activesupport (= 3.0.1)
|
64
|
-
bundler (~> 1.0.0)
|
65
|
-
railties (= 3.0.1)
|
66
|
-
railties (3.0.1)
|
67
|
-
actionpack (= 3.0.1)
|
68
|
-
activesupport (= 3.0.1)
|
69
|
-
rake (>= 0.8.4)
|
70
|
-
thor (~> 0.14.0)
|
71
|
-
rake (0.8.7)
|
72
|
-
rcov (0.9.9)
|
73
|
-
rspec (2.0.1)
|
74
|
-
rspec-core (~> 2.0.1)
|
75
|
-
rspec-expectations (~> 2.0.1)
|
76
|
-
rspec-mocks (~> 2.0.1)
|
77
|
-
rspec-core (2.0.1)
|
78
|
-
rspec-expectations (2.0.1)
|
79
|
-
diff-lcs (>= 1.1.2)
|
80
|
-
rspec-mocks (2.0.1)
|
81
|
-
rspec-core (~> 2.0.1)
|
82
|
-
rspec-expectations (~> 2.0.1)
|
83
|
-
rubyforge (2.0.4)
|
84
|
-
json_pure (>= 1.1.7)
|
85
|
-
sqlite3-ruby (1.3.1)
|
86
|
-
thor (0.14.3)
|
87
|
-
treetop (1.4.8)
|
88
|
-
polyglot (>= 0.3.1)
|
89
|
-
tzinfo (0.3.23)
|
90
|
-
|
91
|
-
PLATFORMS
|
92
|
-
ruby
|
93
|
-
|
94
|
-
DEPENDENCIES
|
95
|
-
jeweler
|
96
|
-
mysql
|
97
|
-
pg
|
98
|
-
rails (= 3.0.1)
|
99
|
-
rcov
|
100
|
-
rspec (= 2.0.1)
|
101
|
-
sqlite3-ruby
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.2.10
|
data/spec/database.yml
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
sqlite3:
|
2
|
-
adapter: sqlite3
|
3
|
-
database: has_person_name.sqlite3
|
4
|
-
|
5
|
-
mysql:
|
6
|
-
adapter: mysql
|
7
|
-
hostname: localhost
|
8
|
-
username: root
|
9
|
-
password: msdb3181
|
10
|
-
database: has_person_name
|
11
|
-
|
12
|
-
postgresql:
|
13
|
-
adapter: postgresql
|
14
|
-
hostname: localhost
|
15
|
-
username: postgres
|
16
|
-
password:
|
17
|
-
database: has_person_name
|
Binary file
|