bb_tag_closer 1.0.0 → 1.0.1

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/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012 Chase
1
+ Copyright (c) 2012 Chase Conklin
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,9 +1,13 @@
1
1
  # BBTagCloser
2
2
 
3
- TODO: Write a gem description
3
+ Automatically detects and closes bb_tags (the ones in forums) in the opposite order that they were added.
4
+
5
+ "[u]My Underlined Text" becomes "[u]My Underlined Text[/u]"
4
6
 
5
7
  ## Installation
6
8
 
9
+ This gem requires Rails 3.2 or later, it was developed and tested on Rails 3.2.9
10
+
7
11
  Add this line to your application's Gemfile:
8
12
 
9
13
  gem 'bb_tag_closer'
@@ -18,8 +22,18 @@ Or install it yourself as:
18
22
 
19
23
  ## Usage
20
24
 
21
- TODO: Write usage instructions here
22
-
25
+ To use on a model, call close_tags. This will automatically close bb_tags on text (not string) attributes of the model. If you wish to manually specify which attributes to close bb_tags on, call close_tags_for like so:
26
+
27
+ close_tags_for :attribute1, attribute2, :on => # callback you wish to close tags on, accepts validation, create, update, and save (is save by default)
28
+
29
+ If the attributes are protected by mass_assignment using the :as option such as attr_accessible :my_attribute, :as => :my_permission; use close_tags or close_tags_for :attribute1, :mass_assignment_keys => :my_permission or close_tags_for :attribute1, :mass_assignment_keys => [:my_permission1, :my_permission2]
30
+
31
+ BBTagCloser closes [b], [i], [u], [s], [quote], [url], [img], [email], [youtube], [size], and [color] tags by default, each is able to accept additional parameters such as [quote=foo]#...[/quote]
32
+ To manually set the tags, call the following in an initializer file:
33
+
34
+ BBTagCloser.configure { |config| config.bb_tags = ["u", "b", "s", "i", "quote", "url", "img", "email", "youtube", "size", "color", # More tags here] }
35
+
36
+
23
37
  ## Contributing
24
38
 
25
39
  1. Fork it
data/changelog.md CHANGED
@@ -1,3 +1,7 @@
1
1
  ## Version 1.0.0 ##
2
2
 
3
- Initial Release
3
+ Initial Release
4
+
5
+ ## Version 1.0.1 ##
6
+
7
+ Added ability to disable tag closing callback by specifying :no_callback => true
@@ -1,3 +1,3 @@
1
1
  module BBTagCloser
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
data/lib/bb_tag_closer.rb CHANGED
@@ -14,34 +14,40 @@ module BBTagCloser
14
14
 
15
15
  module ClassMethods
16
16
 
17
- # Text attributes are considered taggable by default
18
- # Using close_tags_for overrides default with custom attributes
17
+ # ActiveRecord text attributes are considered taggable by default.
18
+ # Using close_tags_for overrides default attributes with custom attributes.
19
19
 
20
20
  def taggable_fields
21
21
  columns.map {|c| {c.name.to_sym => c.type}}.delete_if {|i| not i.value? :text}.map(&:keys).flatten
22
22
  end
23
23
 
24
24
  # Closes tags on text attributes.
25
- # Closes tags before save by default, but can be overridden by passing :on
26
- # the :on paramater accepts :save, :create, :update, :validation
25
+ # Closes tags before save by default, but can be overridden by passing :on;
26
+ # the :on paramater accepts :save, :create, :update, :validation.
27
+ # Alternatively, pass :no_callback => true to prevent tags from being closed automatically
28
+ # (you will have to close them in the controller).
27
29
  # If custom mass_assignment is used such as attr_accessible :foo, :as => :bar
28
- # pass :mass_assignment_keys => :bar or :mass_assignment_keys => [:bar, :baz]
29
-
30
+ # pass :mass_assignment_keys => :bar or :mass_assignment_keys => [:bar, :baz].
31
+
30
32
  def close_tags(options = {})
31
- target = options[:on] ? "before_#{options[:on]}" : "before_save"
32
- send(target, :close_tags)
33
+ unless options[:no_callback]
34
+ target = options[:on] ? "before_#{options[:on]}" : "before_save"
35
+ send(target, :close_tags)
36
+ end
33
37
  mass_assignment_keys = Array options[:mass_assignment_keys]
34
38
  mass_assignment_keys.each do |key|
35
39
  attr_accessible :font_size, :font_color, :as => key
36
40
  end
37
41
  end
38
42
 
39
- # Specify which attributes to close tags on. Accepts the same options as close_tags
43
+ # Specify which attributes to close tags on. Accepts the same options as close_tags.
40
44
 
41
45
  def close_tags_for(*args)
42
46
  options = args.last.is_a?(Hash) ? args.pop : {}
43
- target = options[:on] ? "before_#{options[:on]}" : "before_save"
44
- send(target, :close_tags)
47
+ unless options[:no_callback]
48
+ target = options[:on] ? "before_#{options[:on]}" : "before_save"
49
+ send(target, :close_tags)
50
+ end
45
51
  self.singleton_class.class_eval do
46
52
  define_method :taggable_fields do
47
53
  args.delete_if {|i| not i.is_a? Symbol}
@@ -51,10 +57,14 @@ module BBTagCloser
51
57
 
52
58
  end
53
59
 
60
+ # Sets configuration options. Currently supports setting of custom bb_tags through BBTagCloser.configure
61
+ # {|config| config.bb_tags = ["u", "b", "s", "i", "quote", "url", "img", "email", "youtube", "size", "color", # additional tags ]}
62
+
54
63
  def self.configure(&block)
55
64
  yield BBTagCloser::Configuration
56
65
  end
57
66
 
67
+ # Called during a callback specified in the :on paramater in close_tags or close_tags_for. Closes forum tags in the opposite order they were added by the user.
58
68
 
59
69
  def close_tags
60
70
  text_attributes = self.class.taggable_fields
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bb_tag_closer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -90,3 +90,4 @@ summary: Allows the customization of tags in an initializer file, and can work w
90
90
  test_files:
91
91
  - spec/bb_tag_closer_spec.rb
92
92
  - spec/spec_helper.rb
93
+ has_rdoc: