class Sculptor::CLI::Create

Public Class Methods

exit_on_failure?() click to toggle source
# File lib/sculptor/cli/create.rb, line 13
def self.exit_on_failure?
  true
end
source_root() click to toggle source
# File lib/sculptor/cli/create.rb, line 9
def self.source_root
  File.join(File.dirname(__FILE__), '..', 'templates', 'model')
end

Public Instance Methods

create(name) click to toggle source
# File lib/sculptor/cli/create.rb, line 18
def create(name)

  dir = Dir.pwd.match(/\/source$/) ? "." : "source"

  model_path = "#{dir}/#{name}"

  say(set_color("Creating model: ", :yellow) + set_color(model_path, :white, :bold))

  is_subdir = name.split('/').count > 1
  parent_path = is_subdir ? model_path.split('/')[0..-2].join('/') : model_path

  @name = name
  @title = options[:title] || ask('Title: ')
  @description = options[:desc] || ask('Description: ')
  @stylesheet = ask('Stylesheet: ')
  @iframe = yes?('Use iframe?')

  @dir = is_subdir ? name.split('/')[0..-2].join('/') : name

  @has_data = if yes?('Include data?')
    @model_name = name.split('/').last
    template 'data', (is_subdir ? model_path : File.join(model_path, name)) + '.yaml'
  end

  template 'template', (is_subdir ? model_path : File.join(model_path, name)) + '.html.slim'

  has_index = File.file?(File.join(parent_path, 'index.html.slim'))
  unless has_index
    template 'index-template', (is_subdir ? File.join(parent_path, 'index') : File.join(model_path, 'index')) + '.html.slim'
  end

  unless @stylesheet.empty?
    stylesheet_path = is_subdir ? Pathname(model_path).join("../#{@stylesheet}").to_s : File.join(model_path, "#{@stylesheet}")
    template 'styles', "#{stylesheet_path}.scss" unless File.file? "#{stylesheet_path}.scss"
  end
end