Class: Moka::LipsumHelpers::Lipsum
- Defined in:
- lib/commands/lib/lipsum_helpers.rb
Class Method Summary collapse
-
.paragraphs(count, &block) ⇒ Object
If called without a block, returns a number of paragraphs of dummy text equal to count (with each paragraph enclosed in <p>…</p>).
-
.sentences(count, &block) ⇒ Object
If called without a block, returns a string of dummy text with a number of sentences equal to count (without any markup).
-
.words(count, &block) ⇒ Object
If called without a block, returns a string of dummy text with a number of words equal to count (space-separated and without any markup).
Class Method Details
.paragraphs(count, &block) ⇒ Object
If called without a block, returns a number of paragraphs of dummy text equal to count (with each paragraph enclosed in <p>…</p>). If a block is given, iteratively calls the block passing each paragraph as argument.
9 10 11 12 13 14 15 16 17 |
# File 'lib/commands/lib/lipsum_helpers.rb', line 9 def self.paragraphs(count, &block) if block_given? count.to_i.times do |i| yield LipsumConstants::PARAGRAPHS[i] end else return LipsumConstants::PARAGRAPHS[0, count].collect{|p| "<p>#{p}</p>\n"}.join end end |
.sentences(count, &block) ⇒ Object
If called without a block, returns a string of dummy text with a number of sentences equal to count (without any markup). If a block is given, iteratively calls the block passing each sentence as argument.
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/commands/lib/lipsum_helpers.rb', line 21 def self.sentences(count, &block) sentences = LipsumConstants::PARAGRAPHS.join.split(/\.\s*/) if block_given? count.to_i.times do |i| yield sentences[i] end else return sentences[0, count].join(". ") end end |
.words(count, &block) ⇒ Object
If called without a block, returns a string of dummy text with a number of words equal to count (space-separated and without any markup). If a block is given, iteratively calls the block passing each word as argument.
Gotcha:
If a block is given, the block is iteratively called passing as arguments only words more than 3 characters long. This way, nice dummy lists and menus can be generated without having to remove very short words.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/commands/lib/lipsum_helpers.rb', line 38 def self.words(count, &block) words = LipsumConstants::PARAGRAPHS.join.split(/[\W+]/) if block_given? shifter = 0 count.to_i.times do |i| if words[i].size > 3 yield words[i].downcase else shifter += 1 end end else return words[0, count].join(" ") end end |