Commit 687058f9 authored by f's avatar f
Browse files

v0.2.1 -- random markdown and fixes

parent 920cf802
......@@ -6,6 +6,7 @@ require 'tty-file'
require 'yaml'
require 'securerandom'
require 'jekyll/utils'
require 'faker'
module Sutty
module Cli
......@@ -29,7 +30,7 @@ module Sutty
TTY::File.create_file path,
YAML.dump(data) +
"---\n\n" +
random_text
(content? ? random_markdown : '')
end
private
......@@ -79,25 +80,17 @@ module Sutty
case data_layout[key]['type']
when 'string' then random_text(1)
when 'text' then random_text(3)
when 'markdown' then random_text(3)
when 'markdown' then random_markdown(3)
when 'number' then random_number(255)
when 'order' then random_number(255)
when 'tel'
require 'fake/phone_number'
Faker::PhoneNumber.phone_number
when 'date'
require 'faker/date'
Faker::Date.in_date_period
when 'tel' then Faker::PhoneNumber.phone_number
when 'date' then Faker::Date.in_date_period
when 'array' then Array.new(random_number(10)) { random_string(random_number(3)) }
when 'predefined_array' then data_layout[key]['values'].keys.sample
when 'boolean' then random_boolean
when 'color' then random_color
when 'email'
require 'faker/internet'
Faker::Internet.email
when 'url'
require 'faker/internet'
Faker::Internet.url
when 'email' then Faker::Internet.email
when 'url' then Faker::Internet.url
when 'file' then random_file
when 'image' then random_file
when 'belongs_to' then random_post(key)
......@@ -106,7 +99,6 @@ module Sutty
when 'locales' then random_posts(key)
when 'related_posts' then random_posts
when 'geo'
require 'faker/address'
{
'lat' => Faker::Address.latitude,
'lng' => Faker::Address.longitude
......@@ -119,19 +111,26 @@ module Sutty
end
def random_text(longitude = nil)
require 'faker'
longitude ||= options['content'] == 'short' ? random_number(5) : random_number(20)
longitude ||= long? ? random_number(20) : random_number(5)
Faker::Lorem.paragraphs(number: longitude).join("\n\n")
end
def random_string(longitude = random_number(10))
require 'faker'
Faker::Lorem.sentence(word_count: longitude)
end
def random_markdown(longitude = nil)
longitude ||= long? ? random_number(20) : random_number(5)
Faker::Markdown.sandwich(sentences: longitude,
repeat: long? ? random_number(5) : 1)
end
def long?
options['content'] == 'long'
end
def random_color
Random.bytes(3).unpack1('H*')
end
......@@ -157,6 +156,14 @@ module Sutty
def random_posts(key = nil)
Array.new(random_number(10)) { random_post(key) }
end
def types
@types ||= data_layout.values.map { |v| v['type'] }.uniq
end
def content?
@content ||= CONTENT_FIELDS.map { |f| types.include? f }.any?
end
end
end
end
......
......@@ -2,6 +2,6 @@
module Sutty
module Cli
VERSION = "0.2.0"
VERSION = "0.2.1"
end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment