html_slicer 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/.gitignore +5 -0
  2. data/CHANGELOG +16 -0
  3. data/Gemfile +4 -0
  4. data/MIT-LICENSE +20 -0
  5. data/README.rdoc +336 -0
  6. data/Rakefile +1 -0
  7. data/app/views/html_slicer/_first_slice.html.erb +10 -0
  8. data/app/views/html_slicer/_first_slice.html.haml +8 -0
  9. data/app/views/html_slicer/_first_slice.html.slim +9 -0
  10. data/app/views/html_slicer/_gap.html.erb +7 -0
  11. data/app/views/html_slicer/_gap.html.haml +7 -0
  12. data/app/views/html_slicer/_gap.html.slim +8 -0
  13. data/app/views/html_slicer/_last_slice.html.erb +10 -0
  14. data/app/views/html_slicer/_last_slice.html.haml +8 -0
  15. data/app/views/html_slicer/_last_slice.html.slim +9 -0
  16. data/app/views/html_slicer/_next_slice.html.erb +10 -0
  17. data/app/views/html_slicer/_next_slice.html.haml +8 -0
  18. data/app/views/html_slicer/_next_slice.html.slim +9 -0
  19. data/app/views/html_slicer/_prev_slice.html.erb +10 -0
  20. data/app/views/html_slicer/_prev_slice.html.haml +8 -0
  21. data/app/views/html_slicer/_prev_slice.html.slim +9 -0
  22. data/app/views/html_slicer/_slice.html.erb +11 -0
  23. data/app/views/html_slicer/_slice.html.haml +9 -0
  24. data/app/views/html_slicer/_slice.html.slim +10 -0
  25. data/app/views/html_slicer/_slicer.html.erb +22 -0
  26. data/app/views/html_slicer/_slicer.html.haml +17 -0
  27. data/app/views/html_slicer/_slicer.html.slim +18 -0
  28. data/config/locales/html_slicer.yml +8 -0
  29. data/html_slicer.gemspec +27 -0
  30. data/lib/html_slicer/config.rb +85 -0
  31. data/lib/html_slicer/engine.rb +4 -0
  32. data/lib/html_slicer/helpers/action_view_extension.rb +92 -0
  33. data/lib/html_slicer/helpers/slicer.rb +184 -0
  34. data/lib/html_slicer/helpers/smart_params.rb +35 -0
  35. data/lib/html_slicer/helpers/tags.rb +100 -0
  36. data/lib/html_slicer/installer.rb +118 -0
  37. data/lib/html_slicer/interface.rb +105 -0
  38. data/lib/html_slicer/models/active_record_extension.rb +22 -0
  39. data/lib/html_slicer/options.rb +60 -0
  40. data/lib/html_slicer/processor.rb +46 -0
  41. data/lib/html_slicer/railtie.rb +15 -0
  42. data/lib/html_slicer/resizing.rb +46 -0
  43. data/lib/html_slicer/slicing.rb +101 -0
  44. data/lib/html_slicer/utilities.rb +132 -0
  45. data/lib/html_slicer/version.rb +3 -0
  46. data/lib/html_slicer.rb +23 -0
  47. metadata +105 -0
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ .DS_Store
2
+ *.gem
3
+ .bundle
4
+ Gemfile.lock
5
+ pkg/*
data/CHANGELOG ADDED
@@ -0,0 +1,16 @@
1
+ == 0.0.4
2
+
3
+ * Bugfixes: with param names again... sorry
4
+
5
+ == 0.0.3
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)
9
+
10
+ == 0.0.2
11
+
12
+ * Added :text_break slicing option.
13
+
14
+ == 0.0.1
15
+
16
+ * Initial release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in html_slicer.gemspec
4
+ gemspec
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Valery Kvon
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,336 @@
1
+ = HtmlSlicer
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*.
5
+
6
+ * Imagine you want to resize <iframe> embeddings from YouTube saved in static content.
7
+
8
+
9
+ == Features
10
+
11
+ === Clean
12
+ Does not globally pollute +Array+, +Hash+, +Object+ or <tt>AR::Base</tt>.
13
+
14
+ === Easy to use
15
+ Bundle the gem, then your models are ready to implement slicing ability.
16
+
17
+ === 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.
19
+
20
+ === 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.
23
+
24
+ === ORM & template engine agnostic
25
+ Supports Rails 3 and multiple template engines (ERB, Haml).
26
+
27
+ === Modern
28
+ The slicer helper outputs the HTML5 <nav> tag by default. Plus, the helper supports Rails 3 unobtrusive Ajax.
29
+
30
+
31
+ == Supported versions
32
+
33
+ * Ruby 1.9.2, 1.9.3
34
+
35
+ * Rails 3.0.x, 3.1, 3.2
36
+
37
+ * Haml 3+
38
+
39
+
40
+ == Install
41
+
42
+ Put this line in your Gemfile:
43
+ gem 'html_slicer'
44
+
45
+ Then bundle:
46
+ % bundle
47
+
48
+
49
+ == Implementation
50
+
51
+ === Basic approach
52
+
53
+ slice <method_name>, <configuration>, [:config => <:style>]*
54
+
55
+ where:
56
+ * <method_name> - any method or local variable which returns source String (can be called with .send()).
57
+ * <configuration> - Hash of configuration options and/or +:config+ parameter.
58
+
59
+ === Basic example
60
+
61
+ class Article < ActiveRecord::Base
62
+ slice :content, :as => :paged, :slice => {:maximum => 20}, :resize => {:width => 300}
63
+ end
64
+
65
+ where:
66
+ * <tt>:content</tt> is an attribute accessor for Article which return a target String object.
67
+ * <tt>:as</tt> is a name of basic accessor for result.
68
+ * <tt>:slice</tt> is a hash of <tt>slicing options</tt> as a part of configuration.
69
+ * <tt>:resize</tt> is a hash of <tt>resizing options</tt> as a part of configuration.
70
+
71
+ You can define any key of configuration you want. Otherwise, default configuration options (if available) will be picked up automatically.
72
+
73
+ Console:
74
+
75
+ @article = Article.find(1)
76
+ @article.content
77
+ # => "Words like violence break the silence\r\nCome crashing in into my little world\r\n<iframe width=\"560\" height=\"315\" src=\"http://www.youtube.com/embed/ms0bd_hCZsk\" frameborder=\"0\" allowfullscreen></iframe>\r\nPainful to me, pierce right through me\r\nCan't you understand, oh my little girl?"
78
+
79
+ @article_paged = @article.paged
80
+ # => "Words like violence bre"
81
+
82
+ * the +nil+ argument assumes it is number +1+.
83
+
84
+ @article_paged.slice!(2)
85
+ # => "ak the silence"
86
+
87
+ * the passed slice number is remembered.
88
+
89
+ @article_paged.slice!(4)
90
+ # => "rld
91
+ <iframe width="300" height="169" src="http://www.youtube.com/embed/ms0bd_hCZsk" frameborder="0" allowfullscreen></iframe>"
92
+
93
+ === Configuration options
94
+
95
+ All configuration keys:
96
+ * <tt>:as</tt> is a name of basic accessor for sliced +object+ (result).
97
+ * <tt>:slice</tt> is a hash of slicing options.
98
+ * <tt>:resize</tt> is a hash of resizing options.
99
+ * <tt>:processors</tt> - processors names.
100
+ * <tt>:window</tt> - parameter for ActionView: The "inner window" size (4 by default).
101
+ * <tt>:outer_window</tt> - parameter for ActionView: The "outer window" size (0 by default).
102
+ * <tt>:left</tt> - parameter for ActionView: The "left outer window" size (0 by default).
103
+ * <tt>:right</tt> - parameter for ActionView: The "right outer window" size (0 by default).
104
+ * <tt>:params</tt> - parameter for ActionView: url_for parameters for the links (:controller, :action, etc.)
105
+ * <tt>:param_name</tt> - parameter for ActionView: parameter name for slice number in the links. Accepts +Symbol+, +String+, +Array+.
106
+ * <tt>:remote</tt> - parameter for ActionView: Ajax? (false by default)
107
+
108
+ * <tt>:config</tt> - special key for using stylized configuration (premature configuration).
109
+
110
+ === Slicing options
111
+
112
+ * <tt>:unit</tt> is a +Regexp/String/Hash+ description of text's units counted to split the text by slices.
113
+ 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.
115
+ * <tt>:maximum</tt> is a +Fixnum+ number of units to be a one slice.
116
+
117
+ If +:unit+ defined as Regexp or String, default value is 300.
118
+
119
+ If +:unit+ defined as Hash, default value is 10.
120
+
121
+ If +:unit+ is default, default value is 2000.
122
+
123
+ * <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.
125
+ * <tt>:limit</tt> - a +Fixnum+ limit number of slices.
126
+ In many cases we just need the first slice to perform it as a partial.
127
+ * <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.
129
+ * <tt>:only</tt> is a +Hash+ or +Array+ of hashes, describes which exactly nodes of HTML content to slice.*
130
+ * <tt>:except</tt> is a +Hash+ or +Array+ of hashes, describes which exactly nodes of HTML content NOT to slice.*
131
+
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
133
+ This is a very flexible utility to navigate via HTML content. Read native documentation for details.
134
+
135
+ For example: ID for <tt><hr class="break"> tag</tt> is a hash: <tt>{:tag => "hr", :attributes => {:class => "break"}}</tt>
136
+
137
+ === Resizing options
138
+
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.
140
+ * <tt>:only</tt> is a +Hash+ or +Array+ of hashes, describes which exactly nodes of HTML content to resize.
141
+ * <tt>:except</tt> is a +Hash+ or +Array+ of hashes, describes which exactly nodes of HTML content NOT to resize.
142
+
143
+ === Processors
144
+
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.
147
+
148
+ Example:
149
+
150
+ # /lib/html_slicer_processors/textilized.rb:
151
+
152
+ class Textilized < HtmlSlicer::Processor
153
+ def make
154
+ ERB::Util.textilize(content)
155
+ end
156
+ end
157
+
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.
162
+
163
+ === Configuration levels
164
+
165
+ There are three levels of configuration. Missing options inherited from upper-level.
166
+
167
+ === Global configuration
168
+
169
+ The top-level configuration at +HtmlSlicer.config+, set required options:
170
+
171
+ window = 4
172
+ outer_window = 0
173
+ left = 0
174
+ right = 0
175
+ param_name = :slice
176
+
177
+ You can override/complete global configuration like:
178
+
179
+ HtmlSlicer.configure do |config|
180
+ config.slice = {:complete => /\s+|\z/, :maximum => 2000}
181
+ config.resize = {:width => 300, :only => {:tag => 'iframe'}}
182
+ config.window = 5
183
+ config.param_name = :any_other_param_name
184
+ end
185
+
186
+ === Stylized configuration
187
+
188
+ Along with common global configuration, you can define stylized configuration passing argument like:
189
+
190
+ HtmlSlicer.configure(:paged) do |config|
191
+ config.as = :page
192
+ config.param_name = :page
193
+ end
194
+
195
+ Missing options inherited from global.
196
+
197
+ === Instance configuration
198
+
199
+ Implementing HtmlSlicer accessor as:
200
+
201
+ slice <method_name>, <configuration>, [:config => <:style>]*
202
+
203
+ we can override/complete any configuration.
204
+
205
+ Using +:config+ key we can use one of stylized configurations like:
206
+
207
+ class Post < ActiveRecord::Base
208
+ slice :content, :config => :paged, :slice = {:complete => /\s+/, :maximum => 3000}
209
+ end
210
+
211
+ Passing the block we get more flexible approach to configure slicer like:
212
+
213
+ class Post < ActiveRecord::Base
214
+ slice :content, :config => :paged, :as => :blabla do |config|
215
+ config.slice[:maximum] = 3000
216
+ config.resize.merge! :only => {:tag => "p"}
217
+ config.processors << :decorated
218
+ end
219
+ end
220
+
221
+ == Views
222
+
223
+ === Presumption
224
+
225
+ Model:
226
+
227
+ class Article < ActiveRecord::Base
228
+ slice :content, :as => :paged, :slice => {:maximum => 1000, :complete => /\s+|\z/}
229
+ end
230
+
231
+ Controller:
232
+
233
+ @article = Article.find(1)
234
+ @article_paged = @article.paged.slice!(params[:slice])
235
+
236
+ On a View just call the +slice+ helper:
237
+ <%= slice @article_paged %>
238
+
239
+ This will render several <tt>?slice=N</tt> slicing links surrounded by an HTML5 <+nav+> tag.
240
+
241
+ === Helpers
242
+
243
+ * the +slice+ helper method
244
+
245
+ <%= slice @article_paged %>
246
+ This would output several slicing links such as <tt>« First ‹ Prev ... 2 3 4 5 6 7 8 9 10 ... Next › Last »</tt>
247
+
248
+ * specifing the "inner window" size (4 by default)
249
+
250
+ <%= slicing @article_paged, :window => 2 %>
251
+ This would output something like <tt>... 5 6 7 8 9 ...</tt> when 7 is the current page.
252
+
253
+ * specifing the "outer window" size (0 by default)
254
+
255
+ <%= slicing @article_paged, :outer_window => 3 %>
256
+ This would output something like <tt>1 2 3 4 ...(snip)... 17 18 19 20</tt> while having 20 slices in total.
257
+
258
+ * outer window can be separetely specified by +left+, +right+ (0 by default)
259
+
260
+ <%= slicing @article_paged, :left => 1, :right => 3 %>
261
+ This would output something like <tt>1 ...(snip)... 18 19 20</tt> while having 20 slices in total.
262
+
263
+ * changing the parameter name (+:param_name+) for the links
264
+
265
+ <%= slicing @article_paged, :param_name => :page %>
266
+ This would modify the query parameter name on each links.
267
+
268
+ * extra parameters (:+params+) for the links
269
+
270
+ <%= 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.
272
+
273
+ * Ajax links (crazy simple, but works perfectly!)
274
+
275
+ <%= slicing @article_paged, :remote => true %>
276
+ This would add <tt>data-remote="true"</tt> to all the links inside.
277
+
278
+ * the +link_to_next_page+ helper method
279
+
280
+ <%= link_to_next_slice @article_paged, 'Next Page' %>
281
+ This simply renders a link to the next slice. This would be helpful for creating "Twitter like" pagination feature.
282
+
283
+ * the +slice_entries_info+ helper method
284
+
285
+ <%= slice_entries_info @users %>
286
+ This renders a helpful message with numbers of displayed vs. total entries.
287
+
288
+ === I18n and labels
289
+
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.
292
+
293
+ en:
294
+ views:
295
+ html_slicer:
296
+ first: "&laquo; First"
297
+ last: "Last &raquo;"
298
+ previous: "&lsaquo; Prev"
299
+ next: "Next &rsaquo;"
300
+ truncate: "..."
301
+
302
+ === Param name
303
+
304
+ You can define +:param_name+ as a +symbol+ or +string+, or as an +array+ of any object that responses +.to_s+ method and returns +string+.
305
+ Passing +array+ is the way to define nested :param_name.
306
+
307
+ Examples:
308
+
309
+ :param_name => :page
310
+ # means you define params[:page] as a slice key.
311
+
312
+ :param_name => [:article, :page]
313
+ # means you define params[:article][:page] as a slice key.
314
+
315
+ == More
316
+
317
+ === Slicing a general String or ActiveModel (or any other) object
318
+
319
+ There is no special approaches. Just +extend+ target class to +HtmlSlicer::Installer+ and call the method +slice+ as described before, like:
320
+
321
+ String.extend HtmlSlicer::Installer
322
+ String.slice :to_s, :as => :page, :config => :for_string
323
+
324
+ == Questions, Feedback
325
+
326
+ Message me, I'll try to help everybody. Github (addagger), no Twitter account, Facebook (http://www.facebook.com/profile.php?id=100002178326782)
327
+
328
+
329
+ == Contributing to HtmlSlicer
330
+
331
+ * Fork, fix, then send me a pull request.
332
+
333
+
334
+ == Copyright
335
+
336
+ Copyright (c) 2012 Valery Kvon. See MIT-LICENSE for further details.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,10 @@
1
+ <%# Link to the "First" slice
2
+ - available local variables
3
+ url: url to the first slice
4
+ current_slice: a slice object for the currently displayed slice
5
+ slice_number: total number of slices
6
+ remote: data-remote
7
+ -%>
8
+ <span class="first">
9
+ <%= link_to_unless current_slice.first?, raw(t 'views.html_slicer.first'), url, :remote => remote %>
10
+ </span>
@@ -0,0 +1,8 @@
1
+ -# Link to the "First" slice
2
+ -# available local variables
3
+ -# url: url to the first slice
4
+ -# current_slice: a slice object for the currently displayed slice
5
+ -# slice_number: total number of slices
6
+ -# remote: data-remote
7
+ %span.first
8
+ = link_to_unless current_slice.first?, raw(t 'views.html_slicer.first'), url, :remote => remote
@@ -0,0 +1,9 @@
1
+ / Link to the "First" slice
2
+ - available local variables
3
+ url : url to the first slice
4
+ current_slice : a slice object for the currently displayed slice
5
+ slice_number : total number of slices
6
+ remote : data-remote
7
+ span.first
8
+ == link_to_unless current_slice.first?, raw(t 'views.html_slicer.first'), url, :remote => remote
9
+ '
@@ -0,0 +1,7 @@
1
+ <%# Non-link tag that stands for skipped slices...
2
+ - available local variables
3
+ current_slice: a slice object for the currently displayed slice
4
+ slice_number: total number of slices
5
+ remote: data-remote
6
+ -%>
7
+ <span class="slice gap"><%= raw(t 'views.html_slicer.truncate') %></span>
@@ -0,0 +1,7 @@
1
+ -# Non-link tag that stands for skipped slices...
2
+ -# available local variables
3
+ -# current_slice: a slice object for the currently displayed slice
4
+ -# slice_number: total number of slices
5
+ -# remote: data-remote
6
+ %span.slice.gap
7
+ = raw(t 'views.html_slicer.truncate')
@@ -0,0 +1,8 @@
1
+ / Non-link tag that stands for skipped slices...
2
+ - available local variables
3
+ current_slice : a slice object for the currently displayed slice
4
+ slice_number : total number of slices
5
+ remote : data-remote
6
+ span.slice.gap
7
+ == raw(t 'views.html_slicer.truncate')
8
+ '
@@ -0,0 +1,10 @@
1
+ <%# Link to the "Last" slice
2
+ - available local variables
3
+ url: url to the last slice
4
+ current_slice: a slice object for the currently displayed slice
5
+ slice_number: total number of slices
6
+ remote: data-remote
7
+ -%>
8
+ <span class="last">
9
+ <%= link_to_unless current_slice.last?, raw(t 'views.html_slicer.last'), url, {:remote => remote} %>
10
+ </span>
@@ -0,0 +1,8 @@
1
+ -# Link to the "Last" slice
2
+ -# available local variables
3
+ -# url: url to the last slice
4
+ -# current_slice: a slice object for the currently displayed slice
5
+ -# slice_number: total number of slices
6
+ -# remote: data-remote
7
+ %span.last
8
+ = link_to_unless current_slice.last?, raw(t 'views.html_slicer.last'), url, {:remote => remote}
@@ -0,0 +1,9 @@
1
+ / Link to the "Last" slice
2
+ - available local variables
3
+ url : url to the last slice
4
+ current_slice : a slice object for the currently displayed slice
5
+ slice_number : total number of slices
6
+ remote : data-remote
7
+ span.last
8
+ == link_to_unless current_slice.last?, raw(t 'views.html_slicer.last'), url, {:remote => remote}
9
+ '
@@ -0,0 +1,10 @@
1
+ <%# Link to the "Next" slice
2
+ - available local variables
3
+ url: url to the next slice
4
+ current_slice: a slice object for the currently displayed slice
5
+ slice_number: total number of slices
6
+ remote: data-remote
7
+ -%>
8
+ <span class="next">
9
+ <%= link_to_unless current_slice.last?, raw(t 'views.html_slicer.next'), url, :rel => 'next', :remote => remote %>
10
+ </span>
@@ -0,0 +1,8 @@
1
+ -# Link to the "Next" slice
2
+ -# available local variables
3
+ -# url: url to the next slice
4
+ -# current_slice: a slice object for the currently displayed slice
5
+ -# slice_number: total number of slices
6
+ -# remote: data-remote
7
+ %span.next
8
+ = link_to_unless current_slice.last?, raw(t 'views.html_slicer.next'), url, :rel => 'next', :remote => remote
@@ -0,0 +1,9 @@
1
+ / Link to the "Next" slice
2
+ - available local variables
3
+ url : url to the next slice
4
+ current_slice : a slice object for the currently displayed slice
5
+ slice_number : total number of slices
6
+ remote : data-remote
7
+ span.next
8
+ == link_to_unless current_slice.last?, raw(t 'views.html_slicer.next'), url, :rel => 'next', :remote => remote
9
+ '
@@ -0,0 +1,10 @@
1
+ <%# Link to the "Previous" slice
2
+ - available local variables
3
+ url: url to the previous slice
4
+ current_slice: a slice object for the currently displayed slice
5
+ slice_number: total number of slices
6
+ remote: data-remote
7
+ -%>
8
+ <span class="prev">
9
+ <%= link_to_unless current_slice.first?, raw(t 'views.html_slicer.previous'), url, :rel => 'prev', :remote => remote %>
10
+ </span>
@@ -0,0 +1,8 @@
1
+ -# Link to the "Previous" slice
2
+ -# available local variables
3
+ -# url: url to the previous slice
4
+ -# current_slice: a slice object for the currently displayed slice
5
+ -# slice_number: total number of slices
6
+ -# remote: data-remote
7
+ %span.prev
8
+ = link_to_unless current_slice.first?, raw(t 'views.html_slicer.previous'), url, :rel => 'prev', :remote => remote
@@ -0,0 +1,9 @@
1
+ / Link to the "Previous" slice
2
+ - available local variables
3
+ url : url to the previous slice
4
+ current_slice : a slice object for the currently displayed slice
5
+ slice_number : total number of slices
6
+ remote : data-remote
7
+ span.prev
8
+ == link_to_unless current_slice.first?, raw(t 'views.html_slicer.previous'), url, :rel => 'prev', :remote => remote
9
+ '
@@ -0,0 +1,11 @@
1
+ <%# Link showing slice number
2
+ - available local variables
3
+ slice: a slice object for "this" slice
4
+ url: url to this slice
5
+ current_slice: a slice object for the currently displayed slice
6
+ slice_number: total number of slices
7
+ remote: data-remote
8
+ -%>
9
+ <span class="slice<%= ' current' if slice.current? %>">
10
+ <%= link_to_unless slice.current?, slice, url, opts = {:remote => remote, :rel => slice.next? ? 'next' : slice.prev? ? 'prev' : nil} %>
11
+ </span>
@@ -0,0 +1,9 @@
1
+ -# Link showing slice number
2
+ -# available local variables
3
+ -# slice: a slice object for "this" slice
4
+ -# url: url to this slice
5
+ -# current_slice: a slice object for the currently displayed slice
6
+ -# slice_number: total number of slices
7
+ -# remote: data-remote
8
+ %span{:class => "slice#{' current' if slice.current?}"}
9
+ = link_to_unless slice.current?, slice, url, {:remote => remote, :rel => slice.next? ? 'next' : slice.prev? ? 'prev' : nil}
@@ -0,0 +1,10 @@
1
+ / Link showing slice number
2
+ - available local variables
3
+ slice : a slice object for "this" slice
4
+ url : url to this slice
5
+ current_slice : a slice object for the currently displayed slice
6
+ slice_number : total number of slices
7
+ remote : data-remote
8
+ span class="slice#{' current' if slice.current?}"
9
+ == link_to_unless slice.current?, slice, url, {:remote => remote, :rel => slice.next? ? 'next' : slice.prev? ? 'prev' : nil}
10
+ '
@@ -0,0 +1,22 @@
1
+ <%# The container tag
2
+ - available local variables
3
+ current_slice: a slice object for the currently displayed slice
4
+ slice_number: total number of slices
5
+ remote: data-remote
6
+ slicer: the slicer that renders the slicer tags inside
7
+ -%>
8
+ <%= slicer.render do -%>
9
+ <nav class="slicer">
10
+ <%= first_slice_tag unless current_slice.first? %>
11
+ <%= prev_slice_tag unless current_slice.first? %>
12
+ <% each_slice do |slice| -%>
13
+ <% if slice.left_outer? || slice.right_outer? || slice.inside_window? -%>
14
+ <%= slice_tag slice %>
15
+ <% elsif !slice.was_truncated? -%>
16
+ <%= gap_tag %>
17
+ <% end -%>
18
+ <% end -%>
19
+ <%= next_slice_tag unless current_slice.last? %>
20
+ <%= last_slice_tag unless current_slice.last? %>
21
+ </nav>
22
+ <% end -%>
@@ -0,0 +1,17 @@
1
+ -# The container tag
2
+ -# available local variables
3
+ -# current_slice: a slice object for the currently displayed slice
4
+ -# slice_number: total number of slices
5
+ -# remote: data-remote
6
+ -# slicer: the slicer that renders the slicer tags inside
7
+ = slicer.render do
8
+ %nav.slicer
9
+ = first_slice_tag unless current_slice.first?
10
+ = prev_slice_tag unless current_slice.first?
11
+ - each_slice do |slice|
12
+ - if slice.left_outer? || slice.right_outer? || slice.inside_window?
13
+ = slice_tag slice
14
+ - elsif !slice.was_truncated?
15
+ = gap_tag
16
+ = next_slice_tag unless current_slice.last?
17
+ = last_slice_tag unless current_slice.last?
@@ -0,0 +1,18 @@
1
+ / The container tag
2
+ - available local variables
3
+ current_slice : a slice object for the currently displayed slice
4
+ slice_number : total number of slices
5
+ remote : data-remote
6
+ slicer : the slicer that renders the slicer tags inside
7
+
8
+ == slicer.render do
9
+ nav.slicer
10
+ == first_slice_tag unless current_slice.first?
11
+ == prev_slice_tag unless current_slice.first?
12
+ - each_slice do |slice|
13
+ - if slice.left_outer? || slice.right_outer? || slice.inside_window?
14
+ == slice_tag slice
15
+ - elsif !slice.was_truncated?
16
+ == gap_tag
17
+ == next_slice_tag unless current_slice.last?
18
+ == last_slice_tag unless current_slice.last?
@@ -0,0 +1,8 @@
1
+ en:
2
+ views:
3
+ html_slicer:
4
+ first: "&laquo; First"
5
+ last: "Last &raquo;"
6
+ previous: "&lsaquo; Prev"
7
+ next: "Next &rsaquo;"
8
+ truncate: "..."