doctor_ipsum 0.1 → 0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/README.md +57 -1
- data/Rakefile +8 -1
- data/lib/doctor_ipsum.rb +1 -0
- data/lib/doctor_ipsum/lorem.rb +9 -3
- data/lib/doctor_ipsum/markdown.rb +69 -0
- data/lib/doctor_ipsum/version.rb +1 -1
- data/spec/markdown_spec.rb +99 -0
- data/spec/paragraph_spec.rb +16 -2
- data/spec/word_spec.rb +0 -18
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f6c9a59f74a88b6cebb6e9da69bf6df6ad52de06
|
4
|
+
data.tar.gz: 7860118a5a625051110a6153ec2f15fca3532a0c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b7ca0c2f89280725db992915368d9deae7e3109c7c016182015621e52946e884daa6ddd876e9e2beb715b1cf8e4843b17b7992ff71ae566088480b11e692b8d1
|
7
|
+
data.tar.gz: 339d8c81acf7865c4449df0344e9ea23183dc105cb4e784ceb10a7cca14b60e141806ce66260d109a7ac6f1ed127234c523fef30f094b800a8d1a002efa6b557
|
data/README.md
CHANGED
@@ -26,7 +26,63 @@ Or install it yourself as:
|
|
26
26
|
|
27
27
|
## Usage
|
28
28
|
|
29
|
-
|
29
|
+
For basic [Faker](https://github.com/stympy/faker) Lorem Ipsum:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
|
33
|
+
DoctorIpsum::Lorem.sentence
|
34
|
+
=> "Qui assumenda mollitia error dolorum nostrum et."
|
35
|
+
|
36
|
+
DoctorIpsum::Lorem.words
|
37
|
+
=> ["sit", "vel", "possimus"]
|
38
|
+
|
39
|
+
...
|
40
|
+
|
41
|
+
```
|
42
|
+
|
43
|
+
For Markdown:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
|
47
|
+
DoctorIpsum::Markdown.header
|
48
|
+
=> "# Aliquam Dolore Voluptatem"
|
49
|
+
|
50
|
+
DoctorIpsum::Markdown.emphasis
|
51
|
+
=> "_qui maxime quia_"
|
52
|
+
|
53
|
+
DoctorIpsum::Markdown.blockquote
|
54
|
+
=> "> Laborum et sed quisquam rerum\n> ipsum. Est soluta omnis fugit\n> unde.
|
55
|
+
Et totam eaque illo\n> exercitationem itaque neque. Hic unde\n> fugit
|
56
|
+
deserunt non et. Et\n> est velit voluptate nemo quia."
|
57
|
+
|
58
|
+
DoctorIpsum::Markdown.list
|
59
|
+
=> "* quis nostrum\n* labore error\n* soluta voluptatem\n* totam expedita\n*
|
60
|
+
dlectus et"
|
61
|
+
|
62
|
+
DoctorIpsum::Markdown.horizontal
|
63
|
+
=> "----------"
|
64
|
+
|
65
|
+
DoctorIpsum::Markdown.link
|
66
|
+
=> "[Dignissimos omnis aut et deleniti](http://google.com \"et\")"
|
67
|
+
|
68
|
+
DoctorIpsum::Markdown.image
|
69
|
+
=> ""
|
71
|
+
|
72
|
+
```
|
73
|
+
|
74
|
+
Most of the above functions also take arguments and can be found by
|
75
|
+
[here](https://github.com/geekjuice/doctor_ipsum/blob/master/lib/doctor_ipsum/markdown.rb)
|
76
|
+
|
77
|
+
|
78
|
+
## Future Plans
|
79
|
+
|
80
|
+
Features to look for in future updates:
|
81
|
+
|
82
|
+
* Code blocks (regular and Github flavor)
|
83
|
+
* More flexibility
|
84
|
+
* Full blog post generator
|
85
|
+
|
30
86
|
|
31
87
|
## Contributing
|
32
88
|
|
data/Rakefile
CHANGED
data/lib/doctor_ipsum.rb
CHANGED
data/lib/doctor_ipsum/lorem.rb
CHANGED
@@ -17,12 +17,18 @@ module DoctorIpsum
|
|
17
17
|
words(num_words, supplemental).join(' ').capitalize + '.'
|
18
18
|
end
|
19
19
|
def sentences(sentence_count = 5, supplemental = false)
|
20
|
-
[].tap { |s|
|
21
|
-
.
|
20
|
+
[].tap { |s|
|
21
|
+
resolve(sentence_count).times { s << sentence(5, supplemental) }
|
22
|
+
}.join(' ')
|
22
23
|
end
|
23
24
|
|
24
25
|
def paragraph(sentence_count = 5, supplemental = false)
|
25
|
-
sentences(sentence_count, supplemental)
|
26
|
+
sentences(resolve(sentence_count), supplemental)
|
27
|
+
end
|
28
|
+
def paragraphs(paragraph_count = 5, supplemental = false)
|
29
|
+
[].tap { |p|
|
30
|
+
resolve(paragraph_count).times { p << paragraph(5, supplemental) }
|
31
|
+
}.join("\n\n")
|
26
32
|
end
|
27
33
|
|
28
34
|
end #END SELF
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module DoctorIpsum
|
2
|
+
class Markdown < Lorem
|
3
|
+
class << self
|
4
|
+
# Uses Atx-style i.e. ## Header
|
5
|
+
def header(input = nil, level = 1)
|
6
|
+
input ||= words
|
7
|
+
resolve_md(input, true).prepend('#'*[0,level,6].sort[1]+' ')
|
8
|
+
end
|
9
|
+
|
10
|
+
# Uses underscore
|
11
|
+
def emphasis(input = nil, level = 1)
|
12
|
+
input ||= words
|
13
|
+
underscore = '_'*[0,level,2].sort[1]
|
14
|
+
resolve_md(input).prepend(underscore).concat(underscore)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Simple Blockquote (no Markdown inside...yet)
|
18
|
+
def blockquote(input = nil, level = 5)
|
19
|
+
inputs ||= sentences
|
20
|
+
[].tap { |x| resolve_md(input).split(' ').each_slice(level) { |s| x << s.join(' ').prepend('> ') } }.join("\n")
|
21
|
+
end
|
22
|
+
|
23
|
+
# Uses *
|
24
|
+
def list(input = nil, level = 2, ordered = false)
|
25
|
+
input ||= words(10)
|
26
|
+
[].tap { |x|
|
27
|
+
resolve_md(input).split(' ').each_slice(level).with_index { |s,i|
|
28
|
+
x << s.join(' ').prepend((ordered ? (i+1).to_s+'.' : '*')+' ')
|
29
|
+
}
|
30
|
+
}.join("\n")
|
31
|
+
end
|
32
|
+
|
33
|
+
# 10 dashes
|
34
|
+
def horizontal
|
35
|
+
'-'*10
|
36
|
+
end
|
37
|
+
|
38
|
+
# Opinionated link format
|
39
|
+
def link
|
40
|
+
url = (rand(0..1)>0 ? 'google.com' : 'github.com/geekjuice/doctor_ipsum')
|
41
|
+
basic_format( nil, url , nil)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Images from placehold.it
|
45
|
+
def image( width = rand(100..500), height = rand(100..500) )
|
46
|
+
url = 'placehold.it/'+width.to_s+'x'+height.to_s
|
47
|
+
basic_format( nil, url, nil).prepend('!')
|
48
|
+
end
|
49
|
+
|
50
|
+
def basic_format( text = nil, url = nil, tag = nil )
|
51
|
+
text ||= sentence.chomp('.')
|
52
|
+
url ||= 'google.com'
|
53
|
+
tag ||= word.join(' ')
|
54
|
+
"[" + text + "](http://" + url + ' "' + tag + '")'
|
55
|
+
end
|
56
|
+
|
57
|
+
end #END SELF
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def self.resolve_md(input, title=false)
|
62
|
+
case input
|
63
|
+
when Array then title ? input.map {|x| x.capitalize}.join(' ') : input.join(' ')
|
64
|
+
else title ? input.split(' ').map {|x| x.capitalize}.join(' ') : input
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
data/lib/doctor_ipsum/version.rb
CHANGED
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'doctor_ipsum'
|
3
|
+
|
4
|
+
describe "DoctorIpsum Markdown: " do
|
5
|
+
let(:md) { DoctorIpsum::Markdown }
|
6
|
+
|
7
|
+
describe 'Header' do
|
8
|
+
it 'should add correct header and length' do
|
9
|
+
100.times do
|
10
|
+
level = rand(1..6)
|
11
|
+
md.header( DoctorIpsum::Lorem.sentence(3), level )[0..level-1].should
|
12
|
+
eq('#'*level)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
it 'should have upper bound of 6' do
|
16
|
+
100.times do
|
17
|
+
md.header( DoctorIpsum::Lorem.sentence(3), rand(1..100) ).count('#').should <= 6
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'Emphasis' do
|
23
|
+
it 'should add correct header and length' do
|
24
|
+
100.times do
|
25
|
+
level = rand(1..2)
|
26
|
+
sentence = DoctorIpsum::Lorem.sentence(3)
|
27
|
+
md.emphasis( sentence, level )[0..level-1].should eq('_'*level)
|
28
|
+
md.emphasis( sentence, level )[-level..-1].should eq('_'*level)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should have upper limit of 2' do
|
33
|
+
100.times do
|
34
|
+
md.emphasis( DoctorIpsum::Lorem.sentence(3), rand(1..100) ).count('_').should <= 4
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe 'Blockquote' do
|
40
|
+
it 'should add > before/after each newline' do
|
41
|
+
100.times do
|
42
|
+
md.blockquote( DoctorIpsum::Lorem.sentence(3), 5 ).split("\n").each do |x|
|
43
|
+
x[0..1].should eq('> ')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe 'List' do
|
50
|
+
it 'should create unordered list' do
|
51
|
+
100.times do
|
52
|
+
md.list( DoctorIpsum::Lorem.words(10) , 3, false).split("\n").each do |x|
|
53
|
+
x[0..1].should eq('* ')
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
it 'should create ordered list' do
|
58
|
+
100.times do
|
59
|
+
md.list( DoctorIpsum::Lorem.words(10) , 3, true).split("\n").each.with_index do |x,i|
|
60
|
+
x[0..2].should eq((i+1).to_s+'. ')
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe 'Code block' do
|
67
|
+
pending 'Basic code block, Github flavor fencing, and code source'
|
68
|
+
end
|
69
|
+
|
70
|
+
describe 'Horizontal rules' do
|
71
|
+
it 'should produce 10 dashes' do
|
72
|
+
md.horizontal.should eq('-'*10)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe 'Links' do
|
77
|
+
simple_link_regex = /\[[^\[\]]+\]\(http[s]?:\/\/[a-zA-Z0-9\/._-]+\s*(")?(?:[^\"]*\"\s*\)|\s*\))/
|
78
|
+
it "should produce correct (opinionated) link format" do
|
79
|
+
100.times { md.link.should match(simple_link_regex) }
|
80
|
+
end
|
81
|
+
pending 'Add other link formats and reference links'
|
82
|
+
end
|
83
|
+
|
84
|
+
describe 'Images' do
|
85
|
+
simple_img_regex = /!\[[^\[\]]+\]\(http[s]?:\/\/[a-zA-Z0-9\/._-]+\s*(")?(?:[^\"]*\"\s*\)|\s*\))/
|
86
|
+
it 'should have correct image format' do
|
87
|
+
100.times { md.image.should match(simple_img_regex) }
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'should produce image with correct placehold.it dims' do
|
91
|
+
100.times do
|
92
|
+
width,height = rand(200..500),rand(200..500)
|
93
|
+
md.image(width, height).should include(width.to_s+"x"+height.to_s)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
pending 'images using local cache'
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
data/spec/paragraph_spec.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'doctor_ipsum'
|
3
3
|
|
4
|
-
describe "DoctorIpsum paragraphs(s): " do
|
4
|
+
describe "DoctorIpsum paragraphs(s) and longer: " do
|
5
5
|
|
6
6
|
let(:lorem) { DoctorIpsum::Lorem }
|
7
7
|
|
8
|
-
describe 'Lorem
|
8
|
+
describe 'Lorem Paragraph' do
|
9
9
|
it 'should output String, not Array' do
|
10
10
|
lorem.paragraph.class.should eq String
|
11
11
|
lorem.paragraph.class.should_not eq Array
|
@@ -19,6 +19,20 @@ describe "DoctorIpsum paragraphs(s): " do
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
+
describe 'Lorem Paragraphs' do
|
23
|
+
it 'should output String, not Array' do
|
24
|
+
lorem.paragraphs.class.should eq String
|
25
|
+
lorem.paragraphs.class.should_not eq Array
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should produce correct number of paragraphs' do
|
29
|
+
100.times do
|
30
|
+
rn = rand(10)
|
31
|
+
lorem.paragraphs(rn,true).split("\n\n").count.should eq(rn)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
22
36
|
end
|
23
37
|
|
24
38
|
|
data/spec/word_spec.rb
CHANGED
@@ -30,15 +30,6 @@ describe "DoctorIpsum word(s): " do
|
|
30
30
|
lorem.words(rn).count.should eq(rn)
|
31
31
|
end
|
32
32
|
end
|
33
|
-
|
34
|
-
it 'should resolve array values' do
|
35
|
-
rn = (1..rand(10)+1).map { rand(10)+1 }
|
36
|
-
lorem.words(rn).should_not raise_error
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'should resolve range values' do
|
40
|
-
lorem.words((1..rand(10)+1)).should_not raise_error
|
41
|
-
end
|
42
33
|
end
|
43
34
|
|
44
35
|
describe 'Lorem words with supplemental' do
|
@@ -52,15 +43,6 @@ describe "DoctorIpsum word(s): " do
|
|
52
43
|
lorem.words(rn,true).count.should eq(rn)
|
53
44
|
end
|
54
45
|
end
|
55
|
-
|
56
|
-
it 'should resolve array values' do
|
57
|
-
rn = (1..rand(10)+1).map { rand(10)+1 }
|
58
|
-
lorem.words(rn,true).should_not raise_error
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'should resolve range values' do
|
62
|
-
lorem.words((1..rand(10)+1), true).should_not raise_error
|
63
|
-
end
|
64
46
|
end
|
65
47
|
|
66
48
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: doctor_ipsum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.2'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nicholas Hwang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-08-
|
11
|
+
date: 2013-08-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|
@@ -83,9 +83,11 @@ files:
|
|
83
83
|
- ipsum_lorem.md
|
84
84
|
- lib/doctor_ipsum.rb
|
85
85
|
- lib/doctor_ipsum/lorem.rb
|
86
|
+
- lib/doctor_ipsum/markdown.rb
|
86
87
|
- lib/doctor_ipsum/version.rb
|
87
88
|
- lib/locales/en.yml
|
88
89
|
- spec/doctor_lorem_spec.rb
|
90
|
+
- spec/markdown_spec.rb
|
89
91
|
- spec/paragraph_spec.rb
|
90
92
|
- spec/sentence_spec.rb
|
91
93
|
- spec/spec_helper.rb
|
@@ -116,6 +118,7 @@ specification_version: 4
|
|
116
118
|
summary: '["Lorem Ipsum generator with Markdown formatting"]'
|
117
119
|
test_files:
|
118
120
|
- spec/doctor_lorem_spec.rb
|
121
|
+
- spec/markdown_spec.rb
|
119
122
|
- spec/paragraph_spec.rb
|
120
123
|
- spec/sentence_spec.rb
|
121
124
|
- spec/spec_helper.rb
|