sanitized_attributes 1.0.3 → 1.1.0

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.
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sanitized_attributes
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
+ - 1
8
9
  - 0
9
- - 3
10
- version: 1.0.3
10
+ version: 1.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matthew Boeh
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-10-11 00:00:00 -07:00
19
+ date: 2011-01-27 00:00:00 -08:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -59,24 +59,15 @@ extra_rdoc_files:
59
59
  - LICENSE
60
60
  - README.rdoc
61
61
  files:
62
- - .document
63
- - .gitignore
64
62
  - LICENSE
65
63
  - README.rdoc
66
- - Rakefile
67
- - VERSION
68
- - lib/sanitized_attributes.rb
69
- - lib/sanitized_attributes/sanitized_attribute.rb
70
- - spec/sanitized_attributes_spec.rb
71
- - spec/spec.opts
72
- - spec/spec_helper.rb
73
64
  has_rdoc: true
74
65
  homepage: http://github.com/mboeh/sanitized_attributes
75
66
  licenses: []
76
67
 
77
68
  post_install_message:
78
- rdoc_options:
79
- - --charset=UTF-8
69
+ rdoc_options: []
70
+
80
71
  require_paths:
81
72
  - lib
82
73
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -104,6 +95,5 @@ rubygems_version: 1.3.7
104
95
  signing_key:
105
96
  specification_version: 3
106
97
  summary: HTML-sanitizing attribute accessors for Ruby and Rails
107
- test_files:
108
- - spec/spec_helper.rb
109
- - spec/sanitized_attributes_spec.rb
98
+ test_files: []
99
+
data/.document DELETED
@@ -1,5 +0,0 @@
1
- README.rdoc
2
- lib/**/*.rb
3
- bin/*
4
- features/**/*.feature
5
- LICENSE
data/.gitignore DELETED
@@ -1,21 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
-
21
- ## PROJECT::SPECIFIC
data/Rakefile DELETED
@@ -1,46 +0,0 @@
1
- require 'rubygems'
2
- require 'rake'
3
-
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "sanitized_attributes"
8
- gem.summary = %Q{HTML-sanitizing attribute accessors for Ruby and Rails}
9
- gem.description = %Q{A wrapper to make automatic sanitization of incoming data easier. Uses the sanitize gem and works in both plain Ruby and Rails projects.}
10
- gem.email = "matthew.boeh@gmail.com"
11
- gem.homepage = "http://github.com/mboeh/sanitized_attributes"
12
- gem.authors = ["Matthew Boeh", "CrowdCompass, Inc."]
13
- gem.add_development_dependency "rspec", ">= 1.2.9"
14
- gem.add_dependency "sanitize", "> 0"
15
- end
16
- Jeweler::GemcutterTasks.new
17
- rescue LoadError
18
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
- end
20
-
21
- require 'spec/rake/spectask'
22
- Spec::Rake::SpecTask.new(:spec) do |spec|
23
- spec.libs << 'lib' << 'spec'
24
- spec.spec_files = FileList['spec/**/*_spec.rb']
25
- end
26
-
27
- Spec::Rake::SpecTask.new(:rcov) do |spec|
28
- spec.libs << 'lib' << 'spec'
29
- spec.pattern = 'spec/**/*_spec.rb'
30
- spec.rcov = true
31
- spec.rcov_opts = ['--exclude', File.expand_path("~/.rvm"), "--exclude", "spec"]
32
- end
33
-
34
- task :spec => :check_dependencies
35
-
36
- task :default => :spec
37
-
38
- require 'rake/rdoctask'
39
- Rake::RDocTask.new do |rdoc|
40
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
41
-
42
- rdoc.rdoc_dir = 'rdoc'
43
- rdoc.title = "sanitized_attributes #{version}"
44
- rdoc.rdoc_files.include('README*')
45
- rdoc.rdoc_files.include('lib/**/*.rb')
46
- end
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 1.0.3
@@ -1,90 +0,0 @@
1
- require 'rubygems'
2
- require 'sanitize'
3
- require 'sanitized_attributes/sanitized_attribute'
4
-
5
- module SanitizedAttributes
6
-
7
- def self.included(into)
8
- into.extend(ClassMethods)
9
- end
10
-
11
- class << self
12
-
13
- def add_option(name, &blk)
14
- @option_transforms = nil
15
- @options ||= {}
16
- @options[name] = blk
17
- end
18
-
19
- def add_profile(name, options = {})
20
- @profiles ||= {}
21
- @profiles[name] = options
22
- end
23
-
24
- def profile(name)
25
- @profiles ||= {}
26
- @profiles[name] || {}
27
- end
28
-
29
- def sanitize_options(options)
30
- pr =
31
- if options.kind_of?(Symbol)
32
- profile(options)
33
- else
34
- options
35
- end
36
- o = merge_options(default_profile, pr)
37
- o
38
- end
39
-
40
- protected
41
-
42
- def default_profile
43
- merge_options(profile(:default), obligatory_options)
44
- end
45
-
46
- def merge_options(ops, new_ops)
47
- final_ops = ops.dup
48
- new_ops.each do |key,val|
49
- old = final_ops[key]
50
- if key == :transformers
51
- final_ops[key] ||= []
52
- final_ops[key] = ([old] + [val]).flatten.uniq.compact
53
- else
54
- final_ops[key] = val
55
- end
56
- final_ops.delete(key) if final_ops[key].nil?
57
- end
58
- return final_ops
59
- end
60
-
61
- def obligatory_options
62
- { :transformers => option_transforms }
63
- end
64
-
65
- def option_transforms
66
- @option_transforms ||=
67
- begin
68
- if @options
69
- @options.map do |name, tproc|
70
- lambda do |env|
71
- tproc.call(env, env[:config][name]) if env[:config][name]
72
- end
73
- end
74
- else
75
- []
76
- end
77
- end
78
- end
79
- end
80
-
81
-
82
- module ClassMethods
83
-
84
- def sanitize_attribute(attr_name, options = {})
85
- SanitizedAttribute.add(self, attr_name, options)
86
- end
87
-
88
- end
89
-
90
- end
@@ -1,48 +0,0 @@
1
- module SanitizedAttributes; class SanitizedAttribute
2
-
3
- def initialize(attr_name, options = {})
4
- @attr_name = attr_name
5
- @options = options
6
- end
7
-
8
- def sanitize(content)
9
- Sanitize.clean(content, sanitize_config)
10
- end
11
-
12
- def define_ar_writer_method(klass)
13
- this = self
14
- attr_name = @attr_name
15
- klass.send(:define_method, "#{@attr_name}=") {|value|
16
- send(:write_attribute, attr_name, this.sanitize(value))
17
- }
18
- end
19
-
20
- def define_writer_method(klass)
21
- this = self
22
- attr_name = @attr_name
23
- klass.send(:define_method, "#{@attr_name}_with_sanitization=") {|value|
24
- send("#{attr_name}_without_sanitization=", this.sanitize(value))
25
- }
26
- end
27
-
28
- protected
29
-
30
- def sanitize_config
31
- SanitizedAttributes.sanitize_options(@options)
32
- end
33
-
34
- class << self
35
-
36
- def add(klass, attr_name, options = {})
37
- attrib = new(attr_name, options)
38
- if klass.respond_to?(:alias_method_chain)
39
- attrib.define_ar_writer_method(klass)
40
- else
41
- attrib.define_writer_method(klass)
42
- klass.send(:alias_method, "#{attr_name}_without_sanitization=", "#{attr_name}=")
43
- klass.send(:alias_method, "#{attr_name}=", "#{attr_name}_with_sanitization=")
44
- end
45
- end
46
-
47
- end
48
- end; end
@@ -1,54 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- describe "SanitizedAttributes" do
4
-
5
- before do
6
- @klass = Class.new do
7
- include SanitizedAttributes
8
- attr_accessor :orz
9
- attr_accessor :vux
10
- end
11
- SanitizedAttributes.add_option(:no_empties) do |env, forbidden_empties|
12
- if env[:node].content.empty?
13
- if forbidden_empties.include?(env[:node_name])
14
- {:node => Nokogiri::XML::Text.new("", env[:node].document)}
15
- end
16
- end
17
- end
18
- SanitizedAttributes.add_profile(:quotes_only, :elements => %w[blockquote])
19
- end
20
-
21
- it "removes all HTML by default" do
22
- @klass.module_eval do
23
- sanitize_attribute :orz
24
- end
25
- obj = @klass.new
26
- obj.orz = "<a>Orz are not *many bubbles* like <p/>*campers*. <p></p>Orz <b>are just</b> Orz. <p>- Orz</p>"
27
- obj.orz.should == "Orz are not *many bubbles* like *campers*. Orz are just Orz. - Orz"
28
- end
29
-
30
- it "allows a default sanitizing profile to be set up" do
31
- SanitizedAttributes.add_profile(:default, Sanitize::Config::BASIC)
32
- @klass.module_eval do
33
- sanitize_attribute :orz
34
- end
35
- obj = @klass.new
36
- obj.orz = "<a>Orz are not *many bubbles* like <p/>*campers*. <p></p>Orz <b>are just</b> Orz. <p>- Orz</p>"
37
- obj.orz.should == "<a rel=\"nofollow\">Orz are not *many bubbles* like <p></p>*campers*. <p></p>Orz <b>are just</b> Orz. <p>- Orz</p></a>"
38
- SanitizedAttributes.add_profile(:default, Sanitize::Config::BASIC.merge(:no_empties => %w[p]))
39
- obj.orz = "<a>Orz are not *many bubbles* like <p/>*campers*. <p></p>Orz <b>are just</b> Orz. <p>- Orz</p>"
40
- obj.orz.should == "<a rel=\"nofollow\">Orz are not *many bubbles* like *campers*. Orz <b>are just</b> Orz. <p>- Orz</p></a>"
41
- end
42
-
43
- it "sanitizes attributes with custom options and profiles" do
44
- @klass.module_eval do
45
- sanitize_attribute :orz, :elements => %w[p], :no_empties => %w[p]
46
- sanitize_attribute :vux, :quotes_only
47
- end
48
- obj = @klass.new
49
- obj.vux = "<blockquote>Our special today is <b>particle fragmentation!</b></blockquote> - VUX"
50
- obj.vux.should == "<blockquote>Our special today is particle fragmentation!</blockquote> - VUX"
51
- obj.orz = "Orz are not *many bubbles* like <p/>*campers*. <p></p>Orz <b>are just</b> Orz. <p>- Orz</p>"
52
- obj.orz.should == "Orz are not *many bubbles* like *campers*. Orz are just Orz. <p>- Orz</p>"
53
- end
54
- end
data/spec/spec.opts DELETED
@@ -1 +0,0 @@
1
- --color
data/spec/spec_helper.rb DELETED
@@ -1,9 +0,0 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__))
2
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
- require 'sanitized_attributes'
4
- require 'spec'
5
- require 'spec/autorun'
6
-
7
- Spec::Runner.configure do |config|
8
-
9
- end