hobofields 0.8.3 → 0.8.4
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/Manifest +4 -0
- data/Rakefile +2 -3
- data/hobofields.gemspec +15 -7
- data/lib/hobo_fields/enum_string.rb +1 -1
- data/lib/hobo_fields/field_spec.rb +4 -4
- data/lib/hobo_fields/html_string.rb +7 -6
- data/lib/hobo_fields/markdown_string.rb +4 -3
- data/lib/hobo_fields/migration_generator.rb +18 -4
- data/lib/hobo_fields/model_extensions.rb +7 -4
- data/lib/hobo_fields/raw_html_string.rb +13 -0
- data/lib/hobo_fields/raw_markdown_string.rb +13 -0
- data/lib/hobo_fields/sanitize_html.rb +20 -0
- data/lib/hobo_fields/serialized_object.rb +15 -0
- data/lib/hobo_fields/textile_string.rb +2 -0
- data/lib/hobo_fields.rb +14 -12
- data/rails_generators/hobo_migration/hobo_migration_generator.rb +18 -1
- metadata +14 -6
data/Manifest
CHANGED
@@ -10,6 +10,10 @@ lib/hobo_fields/markdown_string.rb
|
|
10
10
|
lib/hobo_fields/migration_generator.rb
|
11
11
|
lib/hobo_fields/model_extensions.rb
|
12
12
|
lib/hobo_fields/password_string.rb
|
13
|
+
lib/hobo_fields/raw_html_string.rb
|
14
|
+
lib/hobo_fields/raw_markdown_string.rb
|
15
|
+
lib/hobo_fields/sanitize_html.rb
|
16
|
+
lib/hobo_fields/serialized_object.rb
|
13
17
|
lib/hobo_fields/text.rb
|
14
18
|
lib/hobo_fields/textile_string.rb
|
15
19
|
lib/hobo_fields.rb
|
data/Rakefile
CHANGED
@@ -8,9 +8,8 @@ Echoe.new('hobofields') do |p|
|
|
8
8
|
p.project = "hobo"
|
9
9
|
|
10
10
|
p.changelog = "CHANGES.txt"
|
11
|
-
p.version = "0.8.
|
11
|
+
p.version = "0.8.4"
|
12
12
|
|
13
|
-
p.dependencies = ['hobosupport
|
13
|
+
p.dependencies = ['hobosupport =0.8.4', 'rails >=2.2.2']
|
14
14
|
p.development_dependencies = []
|
15
15
|
end
|
16
|
-
|
data/hobofields.gemspec
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
|
2
|
-
# Gem::Specification for Hobofields-0.8.
|
2
|
+
# Gem::Specification for Hobofields-0.8.4
|
3
3
|
# Originally generated by Echoe
|
4
4
|
|
5
5
|
--- !ruby/object:Gem::Specification
|
6
6
|
name: hobofields
|
7
7
|
version: !ruby/object:Gem::Version
|
8
|
-
version: 0.8.
|
8
|
+
version: 0.8.4
|
9
9
|
platform: ruby
|
10
10
|
authors:
|
11
11
|
- Tom Locke
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
|
15
|
-
date: 2008-
|
15
|
+
date: 2008-12-06 00:00:00 +00:00
|
16
16
|
default_executable:
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
@@ -21,9 +21,9 @@ dependencies:
|
|
21
21
|
version_requirement:
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.8.
|
26
|
+
version: 0.8.4
|
27
27
|
version:
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: rails
|
@@ -33,7 +33,7 @@ dependencies:
|
|
33
33
|
requirements:
|
34
34
|
- - ">="
|
35
35
|
- !ruby/object:Gem::Version
|
36
|
-
version:
|
36
|
+
version: 2.2.2
|
37
37
|
version:
|
38
38
|
description: Rich field types and migration generator for Rails
|
39
39
|
email: tom@tomlocke.com
|
@@ -52,6 +52,10 @@ extra_rdoc_files:
|
|
52
52
|
- lib/hobo_fields/migration_generator.rb
|
53
53
|
- lib/hobo_fields/model_extensions.rb
|
54
54
|
- lib/hobo_fields/password_string.rb
|
55
|
+
- lib/hobo_fields/raw_html_string.rb
|
56
|
+
- lib/hobo_fields/raw_markdown_string.rb
|
57
|
+
- lib/hobo_fields/sanitize_html.rb
|
58
|
+
- lib/hobo_fields/serialized_object.rb
|
55
59
|
- lib/hobo_fields/text.rb
|
56
60
|
- lib/hobo_fields/textile_string.rb
|
57
61
|
- lib/hobo_fields.rb
|
@@ -71,6 +75,10 @@ files:
|
|
71
75
|
- lib/hobo_fields/migration_generator.rb
|
72
76
|
- lib/hobo_fields/model_extensions.rb
|
73
77
|
- lib/hobo_fields/password_string.rb
|
78
|
+
- lib/hobo_fields/raw_html_string.rb
|
79
|
+
- lib/hobo_fields/raw_markdown_string.rb
|
80
|
+
- lib/hobo_fields/sanitize_html.rb
|
81
|
+
- lib/hobo_fields/serialized_object.rb
|
74
82
|
- lib/hobo_fields/text.rb
|
75
83
|
- lib/hobo_fields/textile_string.rb
|
76
84
|
- lib/hobo_fields.rb
|
@@ -122,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
130
|
requirements: []
|
123
131
|
|
124
132
|
rubyforge_project: hobo
|
125
|
-
rubygems_version: 1.
|
133
|
+
rubygems_version: 1.3.1
|
126
134
|
specification_version: 2
|
127
135
|
summary: Rich field types and migration generator for Rails
|
128
136
|
test_files:
|
@@ -27,7 +27,7 @@ module HoboFields
|
|
27
27
|
values = values.*.to_s
|
28
28
|
c = Class.new(EnumString) do
|
29
29
|
values.each do |v|
|
30
|
-
const_name = v.upcase
|
30
|
+
const_name = v.upcase.gsub(/[^a-z0-9_]/i, '_').gsub(/_+/, '_')
|
31
31
|
const_set(const_name, self.new(v)) unless const_defined?(const_name)
|
32
32
|
|
33
33
|
method_name = "is_#{v.underscore}?"
|
@@ -49,10 +49,10 @@ module HoboFields
|
|
49
49
|
def different_to?(col_spec)
|
50
50
|
sql_type != col_spec.type ||
|
51
51
|
begin
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
52
|
+
check_attributes = [:null, :default]
|
53
|
+
check_attributes += [:precision, :scale] if sql_type == :decimal
|
54
|
+
check_attributes << :limit if sql_type.in?([:string, :text, :binary, :integer])
|
55
|
+
check_attributes.any? { |k| col_spec.send(k) != self.send(k) }
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
@@ -1,13 +1,14 @@
|
|
1
1
|
module HoboFields
|
2
|
+
|
3
|
+
class HtmlString < RawHtmlString
|
2
4
|
|
3
|
-
|
4
|
-
|
5
|
-
def
|
6
|
-
|
5
|
+
include SanitizeHtml
|
6
|
+
|
7
|
+
def self.declared(model, name, options)
|
8
|
+
model.before_save { |record| record[name] = HoboFields::SanitizeHtml.sanitize(record[name]) }
|
7
9
|
end
|
8
|
-
|
10
|
+
|
9
11
|
HoboFields.register_type(:html, self)
|
10
|
-
|
11
12
|
end
|
12
13
|
|
13
14
|
end
|
@@ -1,11 +1,12 @@
|
|
1
1
|
module HoboFields
|
2
2
|
|
3
|
-
class MarkdownString <
|
3
|
+
class MarkdownString < RawMarkdownString
|
4
|
+
include SanitizeHtml
|
4
5
|
|
5
6
|
HoboFields.register_type(:markdown, self)
|
6
|
-
|
7
|
+
|
7
8
|
def to_html(xmldoctype = true)
|
8
|
-
blank? ? "" : BlueCloth.new(self).to_html
|
9
|
+
blank? ? "" : HoboFields::SanitizeHtml.sanitize(BlueCloth.new(self).to_html)
|
9
10
|
end
|
10
11
|
|
11
12
|
end
|
@@ -17,13 +17,17 @@ module HoboFields
|
|
17
17
|
g.generate
|
18
18
|
end
|
19
19
|
|
20
|
-
def initialize(
|
21
|
-
|
20
|
+
def initialize(*args)
|
21
|
+
options = args.extract_options!
|
22
|
+
@ambiguity_resolver = args.first
|
22
23
|
@drops = []
|
23
24
|
@renames = nil
|
25
|
+
@force_drop = options[:force_drop]
|
24
26
|
end
|
25
27
|
|
26
28
|
attr_accessor :renames
|
29
|
+
|
30
|
+
def force_drop?; @force_drop end
|
27
31
|
|
28
32
|
|
29
33
|
def load_rails_models
|
@@ -76,7 +80,11 @@ module HoboFields
|
|
76
80
|
# return a hash of table renames and modifies the passed arrays so
|
77
81
|
# that renamed tables are no longer listed as to_create or to_drop
|
78
82
|
def extract_table_renames!(to_create, to_drop)
|
79
|
-
if
|
83
|
+
if force_drop?
|
84
|
+
# no renames at all
|
85
|
+
{}
|
86
|
+
|
87
|
+
elsif renames
|
80
88
|
# A hash of table renames has been provided
|
81
89
|
|
82
90
|
to_rename = {}
|
@@ -102,7 +110,11 @@ module HoboFields
|
|
102
110
|
|
103
111
|
|
104
112
|
def extract_column_renames!(to_add, to_remove, table_name)
|
105
|
-
if
|
113
|
+
if force_drop?
|
114
|
+
# no renames at all
|
115
|
+
{}
|
116
|
+
|
117
|
+
elsif renames
|
106
118
|
to_rename = {}
|
107
119
|
column_renames = renames._?[table_name.to_sym]
|
108
120
|
if column_renames
|
@@ -129,6 +141,8 @@ module HoboFields
|
|
129
141
|
|
130
142
|
def always_ignore_tables
|
131
143
|
sessions_table = CGI::Session::ActiveRecordStore::Session.table_name if
|
144
|
+
defined?(CGI::Session::ActiveRecordStore::Session) &&
|
145
|
+
defined?(ActionController::Base) &&
|
132
146
|
ActionController::Base.session_store == CGI::Session::ActiveRecordStore
|
133
147
|
['schema_info', 'schema_migrations', sessions_table].compact
|
134
148
|
end
|
@@ -20,6 +20,7 @@ module HoboFields
|
|
20
20
|
fields do |f|
|
21
21
|
f.field(inheritance_column, :string)
|
22
22
|
end
|
23
|
+
super
|
23
24
|
end
|
24
25
|
|
25
26
|
|
@@ -51,9 +52,9 @@ module HoboFields
|
|
51
52
|
if type
|
52
53
|
type = HoboFields.to_class(type)
|
53
54
|
attrs.each do |attr|
|
54
|
-
declare_attr_type attr, type
|
55
|
+
declare_attr_type attr, type, options
|
55
56
|
define_method "#{attr}=" do |val|
|
56
|
-
if !val.is_a?(type) && HoboFields.can_wrap?(val)
|
57
|
+
if !val.is_a?(type) && HoboFields.can_wrap?(type, val)
|
57
58
|
val = type.new(val.to_s)
|
58
59
|
end
|
59
60
|
instance_variable_set("@#{attr}", val)
|
@@ -94,8 +95,10 @@ module HoboFields
|
|
94
95
|
# Declare a rich-type for any attribute (i.e. getter method). This
|
95
96
|
# does not effect the attribute in any way - it just records the
|
96
97
|
# metadata.
|
97
|
-
def self.declare_attr_type(name, type)
|
98
|
+
def self.declare_attr_type(name, type, options={})
|
99
|
+
klass = HoboFields.to_class(type)
|
98
100
|
attr_types[name] = HoboFields.to_class(type)
|
101
|
+
klass.try.declared(self, name, options)
|
99
102
|
end
|
100
103
|
|
101
104
|
|
@@ -107,7 +110,7 @@ module HoboFields
|
|
107
110
|
options = args.extract_options!
|
108
111
|
try.field_added(name, type, args, options)
|
109
112
|
add_validations_for_field(name, type, args, options)
|
110
|
-
declare_attr_type(name, type) unless HoboFields.plain_type?(type)
|
113
|
+
declare_attr_type(name, type, options) unless HoboFields.plain_type?(type)
|
111
114
|
field_specs[name] = FieldSpec.new(self, name, type, options)
|
112
115
|
attr_order << name unless name.in?(attr_order)
|
113
116
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module HoboFields
|
2
|
+
|
3
|
+
module SanitizeHtml
|
4
|
+
|
5
|
+
PERMITTED_TAGS = %w(a abbr acronym address b bdo big blockquote br caption center cite code colgroup dd del dfn dir
|
6
|
+
div dl dt em fieldset font h1 h2 h3 h4 h5 h6 i img ins kbd label legend li map menu ol optgroup
|
7
|
+
option p pre q s samp select small span strike strong sub sup tbody td textarea tfoot
|
8
|
+
th thead tr tt u ul var)
|
9
|
+
|
10
|
+
PERMITTED_ATTRIBUTES = %w(href title class style align name src label target)
|
11
|
+
|
12
|
+
class Helper; include ActionView::Helpers::SanitizeHelper; extend ActionView::Helpers::SanitizeHelper::ClassMethods; end
|
13
|
+
|
14
|
+
def self.sanitize(s)
|
15
|
+
Helper.new.sanitize(s, :tags => PERMITTED_TAGS, :attributes => PERMITTED_ATTRIBUTES)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
data/lib/hobo_fields.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'hobosupport'
|
2
2
|
|
3
|
-
|
3
|
+
ActiveSupport::Dependencies.load_paths |= [ File.dirname(__FILE__) ]
|
4
4
|
|
5
5
|
module Hobo
|
6
6
|
# Empty class to represent the boolean type.
|
@@ -9,7 +9,7 @@ end
|
|
9
9
|
|
10
10
|
module HoboFields
|
11
11
|
|
12
|
-
VERSION = "0.8.
|
12
|
+
VERSION = "0.8.4"
|
13
13
|
|
14
14
|
extend self
|
15
15
|
|
@@ -26,16 +26,19 @@ module HoboFields
|
|
26
26
|
}
|
27
27
|
|
28
28
|
# Provide a lookup for these rather than loading them all preemptively
|
29
|
+
|
29
30
|
STANDARD_TYPES = {
|
30
31
|
:html => "HtmlString",
|
31
32
|
:markdown => "MarkdownString",
|
32
33
|
:textile => "TextileString",
|
33
34
|
:password => "PasswordString",
|
34
35
|
:text => "Text",
|
35
|
-
:email_address => "EmailAddress"
|
36
|
+
:email_address => "EmailAddress",
|
37
|
+
:serialized => "SerializedObject"
|
36
38
|
}
|
37
39
|
|
38
|
-
@field_types =
|
40
|
+
@field_types = PLAIN_TYPES.with_indifferent_access
|
41
|
+
|
39
42
|
@never_wrap_types = Set.new([NilClass, Hobo::Boolean, TrueClass, FalseClass])
|
40
43
|
|
41
44
|
attr_reader :field_types
|
@@ -55,10 +58,10 @@ module HoboFields
|
|
55
58
|
end
|
56
59
|
|
57
60
|
|
58
|
-
def can_wrap?(val)
|
59
|
-
# Make sure we get the *real* class
|
60
|
-
|
61
|
-
!@never_wrap_types.any? { |c| klass <= c }
|
61
|
+
def can_wrap?(type, val)
|
62
|
+
klass = Object.instance_method(:class).bind(val).call # Make sure we get the *real* class
|
63
|
+
arity = type.instance_method(:initialize).arity
|
64
|
+
(arity == 1 || arity == -1) && !@never_wrap_types.any? { |c| klass <= c }
|
62
65
|
end
|
63
66
|
|
64
67
|
|
@@ -107,8 +110,8 @@ module HoboFields
|
|
107
110
|
# value if we have a special type defined
|
108
111
|
src = if connected? && (type_wrapper = try.attr_type(symbol)) &&
|
109
112
|
type_wrapper.is_a?(Class) && type_wrapper.not_in?(HoboFields::PLAIN_TYPES.values)
|
110
|
-
"val = begin; #{access_code}; end; " +
|
111
|
-
"if HoboFields.can_wrap?(val);
|
113
|
+
"val = begin; #{access_code}; end; wrapper_type = self.class.attr_type(:#{attr_name}); " +
|
114
|
+
"if HoboFields.can_wrap?(wrapper_type, val); wrapper_type.new(val); else; val; end"
|
112
115
|
else
|
113
116
|
access_code
|
114
117
|
end
|
@@ -121,7 +124,7 @@ module HoboFields
|
|
121
124
|
src = if connected? && (type_wrapper = try.attr_type(attr_name)) &&
|
122
125
|
type_wrapper.is_a?(Class) && type_wrapper.not_in?(HoboFields::PLAIN_TYPES.values)
|
123
126
|
"begin; wrapper_type = self.class.attr_type(:#{attr_name}); " +
|
124
|
-
"if !val.is_a?(wrapper_type) && HoboFields.can_wrap?(val); wrapper_type.new(val); else; val; end; end"
|
127
|
+
"if !val.is_a?(wrapper_type) && HoboFields.can_wrap?(wrapper_type, val); wrapper_type.new(val); else; val; end; end"
|
125
128
|
else
|
126
129
|
"val"
|
127
130
|
end
|
@@ -132,7 +135,6 @@ module HoboFields
|
|
132
135
|
|
133
136
|
end
|
134
137
|
|
135
|
-
|
136
138
|
end
|
137
139
|
|
138
140
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../../lib/hobofields'
|
2
2
|
class HoboMigrationGenerator < Rails::Generator::Base
|
3
3
|
|
4
|
+
default_options :force_drop => false
|
5
|
+
|
4
6
|
def initialize(runtime_args, runtime_options = {})
|
5
7
|
super
|
6
8
|
@migration_name = runtime_args.first || begin
|
@@ -27,7 +29,7 @@ class HoboMigrationGenerator < Rails::Generator::Base
|
|
27
29
|
def manifest
|
28
30
|
return record {|m| } if migrations_pending?
|
29
31
|
|
30
|
-
generator = HoboFields::MigrationGenerator.new(self)
|
32
|
+
generator = HoboFields::MigrationGenerator.new(self, :force_drop => options[:force_drop])
|
31
33
|
up, down = generator.generate
|
32
34
|
|
33
35
|
if up.blank?
|
@@ -117,6 +119,21 @@ class HoboMigrationGenerator < Rails::Generator::Base
|
|
117
119
|
system "rake db:migrate"
|
118
120
|
end
|
119
121
|
end
|
122
|
+
|
123
|
+
protected
|
124
|
+
def banner
|
125
|
+
"Usage: #{$0} #{spec.name} [<migration-name>] [--force-drop]"
|
126
|
+
end
|
127
|
+
|
128
|
+
def add_options!(opt)
|
129
|
+
opt.separator ''
|
130
|
+
opt.separator 'Options:'
|
131
|
+
opt.on("--force-drop",
|
132
|
+
"Don't prompt to disambiguate drops from renames - drop everything") do |v|
|
133
|
+
options[:force_drop] = true
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
120
137
|
|
121
138
|
end
|
122
139
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hobofields
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Locke
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-12-06 00:00:00 +00:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -18,9 +18,9 @@ dependencies:
|
|
18
18
|
version_requirement:
|
19
19
|
version_requirements: !ruby/object:Gem::Requirement
|
20
20
|
requirements:
|
21
|
-
- - "
|
21
|
+
- - "="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 0.8.
|
23
|
+
version: 0.8.4
|
24
24
|
version:
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rails
|
@@ -30,7 +30,7 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 2.2.2
|
34
34
|
version:
|
35
35
|
description: Rich field types and migration generator for Rails
|
36
36
|
email: tom@tomlocke.com
|
@@ -49,6 +49,10 @@ extra_rdoc_files:
|
|
49
49
|
- lib/hobo_fields/migration_generator.rb
|
50
50
|
- lib/hobo_fields/model_extensions.rb
|
51
51
|
- lib/hobo_fields/password_string.rb
|
52
|
+
- lib/hobo_fields/raw_html_string.rb
|
53
|
+
- lib/hobo_fields/raw_markdown_string.rb
|
54
|
+
- lib/hobo_fields/sanitize_html.rb
|
55
|
+
- lib/hobo_fields/serialized_object.rb
|
52
56
|
- lib/hobo_fields/text.rb
|
53
57
|
- lib/hobo_fields/textile_string.rb
|
54
58
|
- lib/hobo_fields.rb
|
@@ -68,6 +72,10 @@ files:
|
|
68
72
|
- lib/hobo_fields/migration_generator.rb
|
69
73
|
- lib/hobo_fields/model_extensions.rb
|
70
74
|
- lib/hobo_fields/password_string.rb
|
75
|
+
- lib/hobo_fields/raw_html_string.rb
|
76
|
+
- lib/hobo_fields/raw_markdown_string.rb
|
77
|
+
- lib/hobo_fields/sanitize_html.rb
|
78
|
+
- lib/hobo_fields/serialized_object.rb
|
71
79
|
- lib/hobo_fields/text.rb
|
72
80
|
- lib/hobo_fields/textile_string.rb
|
73
81
|
- lib/hobo_fields.rb
|
@@ -119,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
127
|
requirements: []
|
120
128
|
|
121
129
|
rubyforge_project: hobo
|
122
|
-
rubygems_version: 1.
|
130
|
+
rubygems_version: 1.3.1
|
123
131
|
signing_key:
|
124
132
|
specification_version: 2
|
125
133
|
summary: Rich field types and migration generator for Rails
|