Module: Autopage
- Included in:
- String
- Defined in:
- lib/autopage.rb
Overview
A Rails Plugin to autogenerate long text content to multipage.
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- VERSION =
'0.0.12'
Class Method Summary collapse
Instance Method Summary collapse
-
#split_page(width = 200) ⇒ Array
Split String into array with fixed length characters.
-
#tab_page(width = 200) ⇒ String
Split String into array with fixed length characters and wrapped into jQuery tabs by idsTab plugin.
Class Method Details
.included(base) ⇒ Object
12 13 14 |
# File 'lib/autopage.rb', line 12 def self.included(base) base.extend ClassMethods end |
Instance Method Details
#split_page(width = 200) ⇒ Array
Split String into array with fixed length characters
"xxxxxxxxx".split_page(3) #=> ['xxx','xxx','xxx']
24 25 26 |
# File 'lib/autopage.rb', line 24 def split_page(width=200) scan(/.{1,#{width}}/m) end |
#tab_page(width = 200) ⇒ String
Split String into array with fixed length characters and wrapped into jQuery tabs by idsTab plugin
"xxxxxx".split_page(3) #=> '<ul class="idTabs"><li><a href='#page1'>1</a></li><li><a href='#page2'>2</a></li></ul><div id='page1'>xxx</div><div id='page2'>xxx</div>'
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/autopage.rb', line 37 def tab_page(width=200) tabs = split_page(width) ret = %{<div id='idTabs'><ul>} tabs.each_with_index do |p,n| ret += %{<li><a href='#page#{n+1}'>#{n+1}</a></li>} end ret += '</ul>' tabs.each_with_index do |p,n| ret += %{<div id='page#{n+1}'>#{p}</div>} end ret += '</div>' ret.strip.chomp end |