html_slicer 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,11 +1,11 @@
1
1
  == 0.0.4
2
2
 
3
- * Bugfixes: with param names again... sorry
3
+ * Bug fixes: with param names again... sorry
4
4
 
5
5
  == 0.0.3
6
6
 
7
- * Bugfixes: block-style configuration return blank hash (override Hash::slice method)
8
- * Bugfixes: inherited configuration isn't pure (added deepcopy method of Hash/Array)
7
+ * Bug fixes: block-style configuration return blank hash (override Hash::slice method)
8
+ * Bug fixes: inherited configuration isn't pure (added deep copy method of Hash/Array)
9
9
 
10
10
  == 0.0.2
11
11
 
data/README.rdoc CHANGED
@@ -1,7 +1,6 @@
1
1
  = HtmlSlicer
2
2
 
3
- A little gem for Rails 3 helps you to implement smart way to split textual content, the quick approach to create 'pageable' views for ActiveRecord Model's attributes or just independent strings or any other Ruby classes.
4
- Or course it can split HTML content. More over, it can 'resize' HTML tags having <tt>width=</tt> attribute*.
3
+ A little gem for Rails 3 helps you implement a smart way to split textual content. This is a quick approach to create pageable views for ActiveRecord Models attributes, just independent strings, or any other Ruby classes. Or course it can split HTML content. More over, it can ‘resize’ HTML tags through <tt>width=</tt> attribute*.
5
4
 
6
5
  * Imagine you want to resize <iframe> embeddings from YouTube saved in static content.
7
6
 
@@ -12,20 +11,19 @@ Or course it can split HTML content. More over, it can 'resize' HTML tags having
12
11
  Does not globally pollute +Array+, +Hash+, +Object+ or <tt>AR::Base</tt>.
13
12
 
14
13
  === Easy to use
15
- Bundle the gem, then your models are ready to implement slicing ability.
14
+ Bundle the gem, then your models are ready to implement slicing.
16
15
 
17
16
  === Flexible configuration
18
- Besides global configuration (default), you can create stylized app-level configurations, also any configuration can be tuned for each single one implementation.
17
+ Besides global configuration (default), you can create stylized app-level configurations; also any configuration can be tuned for every single implementation.
19
18
 
20
19
  === Flexible options
21
- You can split your text by any Regexp clause, set up which node of HTML content you want to split, or which you don't. You can also use <tt>processor(s)</tt> to transform the content before it has to be sliced. Param name, used as slice number key accessor, supports to be nested in other one param key (nested params).
22
- <tt>Resizing</tt> HTML tags having <tt>width=</tt> attribute - is a nice feature too.
20
+ You can split your text with any Regexp clause: set up which node from your HTML content you want to split, or which you dont want to. You can also use processor(s) to transform the content before it has to be sliced. Param name, used as a (или the?) slice number key accessor, can be nested in another param key (nested params). Resizing HTML tags having <tt>width=</tt> attribute is a helpful feature too.
23
21
 
24
22
  === ORM & template engine agnostic
25
23
  Supports Rails 3 and multiple template engines (ERB, Haml).
26
24
 
27
25
  === Modern
28
- The slicer helper outputs the HTML5 <nav> tag by default. Plus, the helper supports Rails 3 unobtrusive Ajax.
26
+ The slicer helper outputs the HTML5 <nav> tag by default. In addition, the helper supports Rails 3 unobtrusive Ajax.
29
27
 
30
28
 
31
29
  == Supported versions
@@ -63,12 +61,12 @@ where:
63
61
  end
64
62
 
65
63
  where:
66
- * <tt>:content</tt> is an attribute accessor for Article which return a target String object.
64
+ * <tt>:content</tt> is an attribute accessor for Article which returns a target String object.
67
65
  * <tt>:as</tt> is a name of basic accessor for result.
68
66
  * <tt>:slice</tt> is a hash of <tt>slicing options</tt> as a part of configuration.
69
67
  * <tt>:resize</tt> is a hash of <tt>resizing options</tt> as a part of configuration.
70
68
 
71
- You can define any key of configuration you want. Otherwise, default configuration options (if available) will be picked up automatically.
69
+ You can define any configuration key you want. Otherwise, default configuration options (if available) will be picked up automatically.
72
70
 
73
71
  Console:
74
72
 
@@ -109,9 +107,9 @@ All configuration keys:
109
107
 
110
108
  === Slicing options
111
109
 
112
- * <tt>:unit</tt> is a +Regexp/String/Hash+ description of text's units counted to split the text by slices.
110
+ * <tt>:unit</tt> is a +Regexp/String/Hash+ description of text units counted to split the text by slices.
113
111
  When value is a +Hash+, it assumes the unit is a HTML tag (look at <tt>:only/:except</tt> options for details).
114
- Undefined value or +nil+ assumes it default Regexp /&#?\w+;|\S/. As you see it counts any regular character/or HTML special character as a unit.
112
+ Undefined value or +nil+ assumes it by default Regexp /&#?\w+;|\S/. As you can see it counts any regular character or HTML special character as a unit.
115
113
  * <tt>:maximum</tt> is a +Fixnum+ number of units to be a one slice.
116
114
 
117
115
  If +:unit+ defined as Regexp or String, default value is 300.
@@ -121,29 +119,28 @@ If +:unit+ defined as Hash, default value is 10.
121
119
  If +:unit+ is default, default value is 2000.
122
120
 
123
121
  * <tt>:complete</tt> is a +Regexp+ description of a character used to complete the slice.
124
- For example in case you want to end the slice with the complete word, using :complete => /\s+|\z/ the counter would continue the slice until the first whitespace character.
122
+ For example, if you want to end the slice with a complete word, using :complete => /s+|z/ the counter would continue the slice until the first whitespace character.
125
123
  * <tt>:limit</tt> - a +Fixnum+ limit number of slices.
126
124
  In many cases we just need the first slice to perform it as a partial.
127
125
  * <tt>:text_break</tt> - a responsible <tt>.to_s</tt> value of text breaks between slices.
128
- It can be suspension points or any other symbol.
126
+ It can be an ellipsis or any other symbol.
129
127
  * <tt>:only</tt> is a +Hash+ or +Array+ of hashes, describes which exactly nodes of HTML content to slice.*
130
128
  * <tt>:except</tt> is a +Hash+ or +Array+ of hashes, describes which exactly nodes of HTML content NOT to slice.*
131
129
 
132
- * Actually the hash is a argument for HTML::Conditions class (the part of ActionPack's html_scanner block). Look at http://github.com/rails/rails/blob/master/actionpack/lib/action_controller/vendor/html-scanner/html/node.rb
130
+ * Actually the hash is an argument for HTML::Conditions class (the part of ActionPack's html_scanner code). Look at http://github.com/rails/rails/blob/master/actionpack/lib/action_controller/vendor/html-scanner/html/node.rb
133
131
  This is a very flexible utility to navigate via HTML content. Read native documentation for details.
134
132
 
135
133
  For example: ID for <tt><hr class="break"> tag</tt> is a hash: <tt>{:tag => "hr", :attributes => {:class => "break"}}</tt>
136
134
 
137
135
  === Resizing options
138
136
 
139
- * <tt>:width</tt> is a Fixnum number of pixels as a target value to squeeze the HTML tag. It does automatically proportional with the +:height+ (if existed). The percentage values ignored.
137
+ * <tt>:width</tt> is a Fixnum number of pixels as a target value to squeeze the HTML tag. It does the resize automatically proportional with the +:height+ (if exists). The percentage values are ignored.
140
138
  * <tt>:only</tt> is a +Hash+ or +Array+ of hashes, describes which exactly nodes of HTML content to resize.
141
139
  * <tt>:except</tt> is a +Hash+ or +Array+ of hashes, describes which exactly nodes of HTML content NOT to resize.
142
140
 
143
141
  === Processors
144
142
 
145
- Used to transform the source text before it sliced. Many of us are using any markup languages for dynamic contents.
146
- This is it. Just create any class as a subclass of HtmlSlicer::Processor, put it in +/lib/html_slicer_processors+ directory and define its name within the +:processors+ option.
143
+ Processors are used to transform the source text before it is sliced. Many of us use various markup languages for dynamic contents. This is basically the same thing. Just create any class as a subclass of HtmlSlicer::Processor, put it in +/lib/html_slicer_processors+ directory and define its name within the +:processors+ option.
147
144
 
148
145
  Example:
149
146
 
@@ -155,18 +152,16 @@ Example:
155
152
  end
156
153
  end
157
154
 
158
- Processor class have to include +make+ method, which return transformed String. The +content+ accessor is a source String.
159
-
160
- Then you can pass the option <tt>:processors=>:textilized</tt>
161
- The value of option can be +Array+ of names, if you use more than one processors.
155
+ Processor class has to include +make+ method, which returns transformed String. The content accessor is a source String.
156
+ Then you can set the option <tt>:processors => :textilized</tt>. The value of option can be Array of names, if you use more than one processor.
162
157
 
163
158
  === Configuration levels
164
159
 
165
- There are three levels of configuration. Missing options inherited from upper-level.
160
+ There are three levels of configuration. Missing options are inherited from upper-level ones.
166
161
 
167
162
  === Global configuration
168
163
 
169
- The top-level configuration at +HtmlSlicer.config+, set required options:
164
+ The top level configuration contains necessary options by default:
170
165
 
171
166
  window = 4
172
167
  outer_window = 0
@@ -174,7 +169,7 @@ The top-level configuration at +HtmlSlicer.config+, set required options:
174
169
  right = 0
175
170
  param_name = :slice
176
171
 
177
- You can override/complete global configuration like:
172
+ You can override/complete global configuration this way:
178
173
 
179
174
  HtmlSlicer.configure do |config|
180
175
  config.slice = {:complete => /\s+|\z/, :maximum => 2000}
@@ -185,30 +180,30 @@ You can override/complete global configuration like:
185
180
 
186
181
  === Stylized configuration
187
182
 
188
- Along with common global configuration, you can define stylized configuration passing argument like:
183
+ Along with common global configuration, you can define stylized configuration passing argument like this:
189
184
 
190
185
  HtmlSlicer.configure(:paged) do |config|
191
186
  config.as = :page
192
187
  config.param_name = :page
193
188
  end
194
189
 
195
- Missing options inherited from global.
190
+ Missing options are inherited from global one.
196
191
 
197
192
  === Instance configuration
198
193
 
199
- Implementing HtmlSlicer accessor as:
194
+ If you implement HtmlSlicer accessor this way:
200
195
 
201
196
  slice <method_name>, <configuration>, [:config => <:style>]*
202
197
 
203
- we can override/complete any configuration.
198
+ you can override/complete any configuration.
204
199
 
205
- Using +:config+ key we can use one of stylized configurations like:
200
+ By applying +:config+ key you can use one of stylized configurations:
206
201
 
207
202
  class Post < ActiveRecord::Base
208
203
  slice :content, :config => :paged, :slice = {:complete => /\s+/, :maximum => 3000}
209
204
  end
210
205
 
211
- Passing the block we get more flexible approach to configure slicer like:
206
+ Through passing the block you get a more flexible approach to configure slicer:
212
207
 
213
208
  class Post < ActiveRecord::Base
214
209
  slice :content, :config => :paged, :as => :blabla do |config|
@@ -245,30 +240,30 @@ This will render several <tt>?slice=N</tt> slicing links surrounded by an HTML5
245
240
  <%= slice @article_paged %>
246
241
  This would output several slicing links such as <tt>« First ‹ Prev ... 2 3 4 5 6 7 8 9 10 ... Next › Last »</tt>
247
242
 
248
- * specifing the "inner window" size (4 by default)
243
+ * specifying the "inner window" size (4 by default)
249
244
 
250
245
  <%= slicing @article_paged, :window => 2 %>
251
246
  This would output something like <tt>... 5 6 7 8 9 ...</tt> when 7 is the current page.
252
247
 
253
- * specifing the "outer window" size (0 by default)
248
+ * specifying the "outer window" size (0 by default)
254
249
 
255
250
  <%= slicing @article_paged, :outer_window => 3 %>
256
251
  This would output something like <tt>1 2 3 4 ...(snip)... 17 18 19 20</tt> while having 20 slices in total.
257
252
 
258
- * outer window can be separetely specified by +left+, +right+ (0 by default)
253
+ * outer window can be separately specified by +left+, +right+ (0 by default)
259
254
 
260
255
  <%= slicing @article_paged, :left => 1, :right => 3 %>
261
256
  This would output something like <tt>1 ...(snip)... 18 19 20</tt> while having 20 slices in total.
262
257
 
263
- * changing the parameter name (+:param_name+) for the links
258
+ * changing the parameter name (:+param_name+) for the links
264
259
 
265
260
  <%= slicing @article_paged, :param_name => :page %>
266
261
  This would modify the query parameter name on each links.
267
262
 
268
- * extra parameters (:+params+) for the links
263
+ * extra parameters (:+params+) for the link
269
264
 
270
265
  <%= slicing @article_paged, :params => {:controller => 'foo', :action => 'show', :id => 21} %>
271
- This would modify each link's +url_option+. :+controller+ and :+action+ might be the keys in common.
266
+ This would modify each link's +url_option+. :+controller+ and :+action+ might be the common keys.
272
267
 
273
268
  * Ajax links (crazy simple, but works perfectly!)
274
269
 
@@ -282,13 +277,12 @@ This will render several <tt>?slice=N</tt> slicing links surrounded by an HTML5
282
277
 
283
278
  * the +slice_entries_info+ helper method
284
279
 
285
- <%= slice_entries_info @users %>
280
+ <%= slice_entries_info @article_paged %>
286
281
  This renders a helpful message with numbers of displayed vs. total entries.
287
282
 
288
283
  === I18n and labels
289
284
 
290
- The default labels for 'first', 'last', 'previous', '...' and 'next' are stored in the I18n yaml inside the engine, and rendered through I18n API. You can switch the label value per I18n.locale for your internationalized application.
291
- Keys and the default values are the following. You can override them by adding to a YAML file in your <tt>Rails.root/config/locales</tt> directory.
285
+ The default labels for first’, last’, previous’, ‘…’ and next are stored in the I18n yaml inside the engine, and rendered through I18n API. You can switch the label value per I18n.locale for your internationalized application. Keys and the default values are listed below. You can override them by adding to a YAML file in your <tt>Rails.root/config/locales</tt> directory.
292
286
 
293
287
  en:
294
288
  views:
@@ -316,19 +310,19 @@ Examples:
316
310
 
317
311
  === Slicing a general String or ActiveModel (or any other) object
318
312
 
319
- There is no special approaches. Just +extend+ target class to +HtmlSlicer::Installer+ and call the method +slice+ as described before, like:
313
+ There is no apecific approach to it. Just extend target class to +HtmlSlicer::Installer+ and call the method slice as described before:
320
314
 
321
315
  String.extend HtmlSlicer::Installer
322
316
  String.slice :to_s, :as => :page, :config => :for_string
323
317
 
324
318
  == Questions, Feedback
325
319
 
326
- Message me, I'll try to help everybody. Github (addagger), no Twitter account, Facebook (http://www.facebook.com/profile.php?id=100002178326782)
320
+ Message me and Ill do my best to help everybody. Github (addagger), no Twitter account, Facebook (http://www.facebook.com/profile.php?id=100002178326782)
327
321
 
328
322
 
329
323
  == Contributing to HtmlSlicer
330
324
 
331
- * Fork, fix, then send me a pull request.
325
+ * Fork, fix, and then send me a pull request.
332
326
 
333
327
 
334
328
  == Copyright
data/html_slicer.gemspec CHANGED
@@ -9,9 +9,9 @@ Gem::Specification.new do |s|
9
9
  s.platform = Gem::Platform::RUBY
10
10
  s.authors = ["Valery Kvon"]
11
11
  s.email = ["addagger@gmail.com"]
12
- s.homepage = %q{http://github.com/addagger/HtmlSlicer}
12
+ s.homepage = %q{http://vkvon.ru/projects/html_slicer}
13
13
  s.summary = %q{HTML text slicer}
14
- s.description = %q{A "smart" way to slice HTMLsed text to pages, also it can optionally resize included "width/height" attributes of HTML tags like <iframe>, <object>, <img> etc.}
14
+ s.description = %q{HtmlSlicer is a smart way to cut an HTML text into pieces. It also provides on option to resize "width"/"height" attributes of HTML tags, such as <iframe>, <object>, <img> or any other.}
15
15
 
16
16
  s.add_development_dependency "actionpack", ['>= 3.0.0']
17
17
 
@@ -31,7 +31,7 @@ module HtmlSlicer
31
31
  # slice :content, :config => :paged
32
32
  # end
33
33
  #
34
- # * Missing required parameters pick up automatically from global configuration set before.
34
+ # * Missing options are inherited from global one.
35
35
  #
36
36
  def self.configure(style = nil, &block)
37
37
  yield eval("@config#{"_#{style}" if style} ||= #{style ? "@config.duplicate" : "Configuration.new"}")
@@ -68,8 +68,8 @@ module HtmlSlicer
68
68
 
69
69
  def duplicate
70
70
  dup = Configuration.new
71
- dup.config.replace(deepcopy(config))
72
- dup
71
+ dup.config.replace(deepcopy(config))
72
+ dup
73
73
  end
74
74
 
75
75
  end
@@ -88,5 +88,5 @@ module HtmlSlicer
88
88
  output.html_safe
89
89
  end
90
90
  end
91
-
91
+
92
92
  end
@@ -2,7 +2,7 @@ module HtmlSlicer
2
2
 
3
3
  class SmartParams < Hash
4
4
  # Implements smart and flexible +params+ merging.
5
- # Method accepts passed +params+ hash and merge it with a new +param_name+ and it's value.
5
+ # Method accepts passed +params+ hash and merge it with a new :+param_name+ and it's value.
6
6
  # In the case when you passed +param_name+ option as an Array, method returns merged new
7
7
  # instance of hashed params where all subhashes merged into the same way.
8
8
  #
@@ -22,8 +22,8 @@ module HtmlSlicer
22
22
  # * <tt>:slice</tt> is a hash of +slicing options+.
23
23
  # * <tt>:resize</tt> is a hash of +resizing options+.
24
24
  #
25
- # You can define any key of configuration you want. Otherwise, default configuration
26
- # will be picked up automatically.
25
+ # You can define any configuration key you want.
26
+ # Otherwise, default configuration options (if available) will be picked up automatically.
27
27
  #
28
28
  # === All configuration keys:
29
29
  # * <tt>:as</tt> is a name of basic accessor for sliced +object+.
@@ -69,7 +69,6 @@ module HtmlSlicer
69
69
  end
70
70
 
71
71
  module NestedMergeHash
72
-
73
72
  include Deepcopy
74
73
 
75
74
  # Return the merged Hash with another +hash+, where the possible child hashes are also merged.
@@ -1,3 +1,3 @@
1
1
  module HtmlSlicer
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: html_slicer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-18 00:00:00.000000000 Z
12
+ date: 2012-02-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionpack
16
- requirement: &70154298274740 !ruby/object:Gem::Requirement
16
+ requirement: &70305272402260 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.0.0
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70154298274740
25
- description: A "smart" way to slice HTMLsed text to pages, also it can optionally
26
- resize included "width/height" attributes of HTML tags like <iframe>, <object>,
27
- <img> etc.
24
+ version_requirements: *70305272402260
25
+ description: HtmlSlicer is a smart way to cut an HTML text into pieces. It also provides
26
+ on option to resize "width"/"height" attributes of HTML tags, such as <iframe>,
27
+ <object>, <img> or any other.
28
28
  email:
29
29
  - addagger@gmail.com
30
30
  executables: []
@@ -77,7 +77,7 @@ files:
77
77
  - lib/html_slicer/slicing.rb
78
78
  - lib/html_slicer/utilities.rb
79
79
  - lib/html_slicer/version.rb
80
- homepage: http://github.com/addagger/HtmlSlicer
80
+ homepage: http://vkvon.ru/projects/html_slicer
81
81
  licenses:
82
82
  - MIT
83
83
  post_install_message: