phil 0.9.1

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.
Files changed (7) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +20 -0
  3. data/README.md +92 -0
  4. data/Rakefile +6 -0
  5. data/lib/phil/version.rb +3 -0
  6. data/lib/phil.rb +132 -0
  7. metadata +119 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a097c29022da4d95864025def83c24f921fbdec6
4
+ data.tar.gz: d0d9c026d74181fb0f0dae4f6c787620706132f5
5
+ SHA512:
6
+ metadata.gz: 01f07b15c56601616045ae7ea1923520006552701b0f31d1e6b92a124a7f899e507dd4d07be9bdd1a013c18766446268f4c37f72182ca58405415ab48a9368cf
7
+ data.tar.gz: 2fad59da69815f4b515c9d99c1045371b0f326355bfcb4070a8ef6275b9e213260eb7e6769ea0afccfc2d1ee132b73f0ced53bea12a3ab016cde4103483ecea7
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 Cameron Daigle
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,92 @@
1
+ # Phil
2
+
3
+ Phil is a lightweight content generation module that wraps around [Ffaker](https://github.com/EmmanuelOga/ffaker/tree/master/lib/ffaker). You can create large amounts of markup for layout testing with a few simple methods.
4
+
5
+ A big theme of Phil is that any parameter that can accept a number also accepts a range. This allows for far more utility than vanilla Ffaker when it comes to testing different permutations of content.
6
+
7
+ ## Iteration
8
+
9
+ Get a random integer from an array or range:
10
+
11
+ ```ruby
12
+ Phil.pick 1..3
13
+ Phil.pick [1, 2, 3]
14
+ Phil.pick ["Foo", "Bar", "Baz"]
15
+ ```
16
+
17
+ Loop a random number of times:
18
+
19
+ ```ruby
20
+ Phil.loop 1..100 do |i|
21
+ "This will be output between 1 and 100 times and is index #{i}"
22
+ end
23
+ ```
24
+
25
+ Have a 1 in N chance of doing something (N defaults to 3):
26
+
27
+ ```ruby
28
+ Phil.sometimes "foo" # 1 in 3
29
+ Phil.sometimes "foo", 100 # 1 in 100
30
+ Phil.sometimes do
31
+ "foo"
32
+ Phil.sometimes 100 do
33
+ "foo"
34
+ ```
35
+
36
+ ## Content Generation
37
+
38
+ ### Body content
39
+
40
+ Generate a ton of body content with one method. This defaults to
41
+ `"h1 p p h2 p ol h2 p ul"`, but you can pass it a string of whatever content tags you like,
42
+ including `blockquote`, other headings, and so on. Blockquotes will contain multiple `<p>` elements, paragraphs will contain a few sentences, and most other tags will contain 3-15 words.
43
+
44
+ ```ruby
45
+ Phil.body_content
46
+ Phil.body_content "h1 p h2 ul p blockquote h5 h6"
47
+ ```
48
+
49
+ ### Lorem methods (all take ranges or numbers)
50
+
51
+ ```ruby
52
+ Phil.words 5
53
+ Phil.words 5..50
54
+
55
+ Phil.paragraphs 5 # outputs HTML markup with <p> elements
56
+ Phil.paragraphs 5..50
57
+
58
+ Phil.blockquote # defaults to containing 1..3 <p> elements
59
+ Phil.blockquote 1..5 # 1..5 <p> elements
60
+
61
+ Phil.ul # defaults to 3..10 <li>s with 3..15 words
62
+ Phil.ul 1..5, 10 # 1..5 items, 10 words apiece
63
+
64
+ Phil.ol
65
+ Phil.ol 1..5, 10
66
+
67
+ Phil.link_list # outputs a <ul> of <li>s with <a>s inside
68
+ Phil.link_list 1..5, 10
69
+ ```
70
+
71
+ ### Assorted other content generation methods
72
+
73
+ ```ruby
74
+ Phil.date # Random date object between Dec 31 1969 and now
75
+ Phil.date 7 # Random date object in the last 7 days
76
+ Phil.currency 10..100 # Price string from $10.00 to $100.00
77
+ Phil.currency 10..100, "£" # Prefix different currency symbol
78
+ Phil.phone # Defaults to (###)-###-####
79
+ Phil.phone "###-#### x###"
80
+ Phil.number 5 # Random 5-digit number (string)
81
+ ```
82
+
83
+ ### Aliased Ffaker methods for convenience
84
+
85
+ ```ruby
86
+ Phil.domain_name
87
+ Phil.email
88
+ Phil.name
89
+ Phil.first_name
90
+ Phil.last_name
91
+ Phil.state_abbr
92
+ ```
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "rspec/core/rake_task"
2
+ RSpec::Core::RakeTask.new(:spec) do |spec|
3
+ spec.pattern = "spec/**/*_spec.rb"
4
+ end
5
+
6
+ task :default => :spec
@@ -0,0 +1,3 @@
1
+ module Phil
2
+ VERSION = '0.9.1'
3
+ end
data/lib/phil.rb ADDED
@@ -0,0 +1,132 @@
1
+ module Phil
2
+
3
+ class << self
4
+
5
+ def pick(num)
6
+ num.respond_to?(:to_a) ? num.to_a.sample : num
7
+ end
8
+
9
+ def loop(num)
10
+ pick(num).times do |i|
11
+ yield(i)
12
+ end
13
+ end
14
+
15
+ def sometimes(num_or_content = 3, num = 3)
16
+ if block_given?
17
+ if num_or_content == pick(1..num_or_content)
18
+ yield
19
+ end
20
+ else
21
+ if num == pick(1..num)
22
+ num_or_content
23
+ end
24
+ end
25
+ end
26
+
27
+ def words(num)
28
+ Faker::Lorem.words(pick(num)).join(' ').html_safe
29
+ end
30
+
31
+ def paragraphs(num)
32
+ content_method = -> { Faker::Lorem.paragraphs(1).join }
33
+ build_tags "p", content_method, pick(num)
34
+ end
35
+
36
+ def ul(list_items = nil, item_length = nil)
37
+ tag "ul", item_length, list_items
38
+ end
39
+
40
+ def ol(list_items = nil, item_length = nil)
41
+ tag "ol", item_length, list_items
42
+ end
43
+
44
+ def blockquote(paragraphs = nil)
45
+ tag "blockquote", paragraphs
46
+ end
47
+
48
+ def link_list(list_items = (3..10), item_length = (1..5))
49
+ build_tag "ul", build_tags("li", -> { "<a href='#'>#{words(item_length)}</a>" }, list_items)
50
+ end
51
+
52
+ def body_content(pattern="h1 p p h2 p ol h2 p ul")
53
+ pattern.split(" ").map{ |t| tag(t) }.join.html_safe
54
+ end
55
+
56
+ def currency(num, symbol = "$")
57
+ val = ((pick(num) * 100) / 100).round(2)
58
+ sprintf("$%.2f", val)
59
+ end
60
+
61
+ def number(length)
62
+ (1..length).map { rand(10) }.join
63
+ end
64
+
65
+ def date(day_window = nil)
66
+ t = Time.now.to_f
67
+ Time.at(day_window ? t - rand * day_window * 86400 : t * rand)
68
+ end
69
+
70
+ def domain_name
71
+ Faker::Internet.domain_name
72
+ end
73
+
74
+ def email
75
+ Faker::Internet.email
76
+ end
77
+
78
+ def first_name
79
+ Faker::Name.first_name
80
+ end
81
+
82
+ def last_name
83
+ Faker::Name.last_name
84
+ end
85
+
86
+ def name
87
+ Faker::Name.name
88
+ end
89
+
90
+ def phone(format = "(###) ###-####")
91
+ format.gsub(/#/) { rand(9) + 1 }
92
+ end
93
+
94
+ def state
95
+ Faker::AddressUS.state
96
+ end
97
+
98
+ def state_abbr
99
+ Faker::AddressUS.state_abbr
100
+ end
101
+
102
+ private
103
+
104
+ def tag(name, content = nil, children = nil)
105
+ case name
106
+ when "ul", "ol"
107
+ content ||= (3..15)
108
+ children ||= (3..10)
109
+ build_tag name, build_tags("li", content, children)
110
+ when "blockquote"
111
+ content ||= (1..3)
112
+ build_tag name, paragraphs(content)
113
+ when "p"
114
+ paragraphs(1)
115
+ else
116
+ content ||= (3..15)
117
+ build_tags name, content
118
+ end
119
+ end
120
+
121
+ def build_tags(name, content, elements = 1)
122
+ content_method = if content.is_a? Proc then content else -> { words(content) } end
123
+ pick(elements).times.map { build_tag(name, content_method.call) }.join.html_safe
124
+ end
125
+
126
+ def build_tag(name, content)
127
+ "<#{name}>#{content}</#{name}>".html_safe
128
+ end
129
+
130
+ end
131
+
132
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: phil
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.1
5
+ platform: ruby
6
+ authors:
7
+ - Cameron Daigle
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ffaker
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: ox
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Phil makes it easy to generate content for your UI mockups.
84
+ email:
85
+ - cameron@hashrocket.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - lib/phil/version.rb
91
+ - lib/phil.rb
92
+ - LICENSE
93
+ - README.md
94
+ - Rakefile
95
+ homepage: https://github.com/camerond/phil
96
+ licenses:
97
+ - MIT
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - '>='
106
+ - !ruby/object:Gem::Version
107
+ version: 1.9.3
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.0.3
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: Phil brings the content.
119
+ test_files: []