Module: SDoc::Helpers
- Included in:
- RDoc::Generator::SDoc
- Defined in:
- lib/sdoc/helpers.rb
Instance Method Summary collapse
- #each_letter_group(methods) {|group| ... } ⇒ Object
-
#strip_tags(text) ⇒ Object
Strips out HTML tags from a given string.
-
#truncate(text, options = {}) ⇒ Object
Truncates a given string.
Instance Method Details
#each_letter_group(methods) {|group| ... } ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/sdoc/helpers.rb', line 2 def each_letter_group(methods, &block) group = {:name => '', :methods => []} methods.sort{ |a, b| a.name <=> b.name }.each do |method| gname = group_name method.name if gname != group[:name] yield group unless group[:methods].size == 0 group = { :name => gname, :methods => [] } end group[:methods].push(method) end yield group unless group[:methods].size == 0 end |
#strip_tags(text) ⇒ Object
Strips out HTML tags from a given string.
Example:
("<strong>Hello world</strong>") => "Hello world"
23 24 25 |
# File 'lib/sdoc/helpers.rb', line 23 def (text) text.gsub(%r{</?[^>]+?>}, "") end |
#truncate(text, options = {}) ⇒ Object
Truncates a given string. It tries to take whole sentences to have a meaningful description for SEO tags.
The only available option is :length
which defaults to 200.
31 32 33 34 35 36 37 38 |
# File 'lib/sdoc/helpers.rb', line 31 def truncate(text, = {}) if text length = .fetch(:length, 200) stop = text.rindex(".", length - 1) || length "#{text[0, stop]}." end end |