Skip to content

Commit

Permalink
Merged pull request #38 from mitchellbryson/master.
Browse files Browse the repository at this point in the history
allow the lorem.date method to accept a range, for more specific dates
  • Loading branch information
blahed committed Apr 29, 2011
2 parents 62d4d29 + afb5b8a commit 5b37c50
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/frank/lorem.rb
Expand Up @@ -45,11 +45,11 @@ def paragraphs(total, replacement = nil)
end
end

def date(fmt = '%a %b %d, %Y', replacement = nil)
def date(fmt = '%a %b %d, %Y', range = 1950..2010, replacement = nil)
if Frank.exporting? && replacement
replacement
else
y = rand(20) + 1990
y = rand(range.last - range.first) + range.first
m = rand(12) + 1
d = rand(31) + 1
Time.local(y,m,d).strftime(fmt)
Expand Down
2 changes: 1 addition & 1 deletion spec/template/dynamic/lorem_test.haml
@@ -1,7 +1,7 @@
%p.words= lorem.words 3, 'replace-this'
%p.sentences= lorem.sentences 2, 'replace-this'
%p.paragraphs= lorem.paragraphs 1, 'replace-this'
%p.date= lorem.date '%Y-%m-%d', 'replace-this'
%p.date= lorem.date '%Y-%m-%d', 1910..1919, 'replace-this'
%p.name= lorem.name 'replace-this'
%p.email= lorem.email 'replace-this'
%img{:src => lorem.image('400x300')}
Expand Down
6 changes: 6 additions & 0 deletions spec/template_helpers_spec.rb
Expand Up @@ -65,6 +65,12 @@ def app
template.should =~ reg
end

it 'render haml with lorem date between 1910 and 1919' do
template = @app.render('lorem_test.haml')
reg = /<p class='date'>191(\d{1})-\d{2}-\d{2}<\/p>/m
template.should =~ reg
end

it 'render image url using imager' do
template = @app.render('lorem_test.haml')
reg1 = /<img src='http:\/\/placehold\.it\/400x300' \/>/
Expand Down

0 comments on commit 5b37c50

Please sign in to comment.