Sha256: 574132076d3689a0125d78164c6091f46e0520ad8f3a16769fc7668339833f33

Contents?: true

Size: 1.48 KB

Versions: 22

Compression:

Stored size: 1.48 KB

Contents

command 'init' do |c|
  c.syntax = 'brief init NAME [OPTIONS]'
  c.description = 'Create a new brief project, aka a briefcase'

  c.option '--root', String, 'The root folder for the new project.'

  c.action do |args, options|
    options.default(root: Dir.pwd)

    if path = args.first
      root = Pathname(options.root).join(path)
    end

    [root, root.join('models'), root.join('docs')].each do |p|
      puts "== folder #{ p.basename } #{ '. exists' if p.exist? }"
      FileUtils.mkdir_p(p) unless p.exist?
    end

    if root.join('brief.rb').exist?
      say '== Briefcase config already exists. Skipping.'
    else
      say '== Creating config file brief.rb'
      root.join('brief.rb').open('w+') do |fh|
        default_config = <<-EOF

config do
  set(:models_path => Pathname(__FILE__).parent.join("models"))
end

define("Post") do
  meta do
    status
    date DateTime, :default => lambda {|post, attr| post.document.created_at }
  end

  content do
    title "h1"
    has_many :subheadings, "h2"
  end

  helpers do
    def publish(options={})
      post.set(:status, "published")
      post.save
    end
  end

  on_status_change(:from => "draft", :to => "published") do |model|
    # Do Something
    # mail_service.send_html_email_campaign(model.to_html)
  end
end

# brief publish posts /path/to/*.html.md
action "publish posts" do |briefcase, models, options|
  models.each do |post|
    post.publish(options)
  end
end
        EOF
        fh.write(default_config)
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
brief-1.8.6 lib/brief/cli/init.rb
brief-1.8.5 lib/brief/cli/init.rb
brief-1.8.4 lib/brief/cli/init.rb
brief-1.8.3 lib/brief/cli/init.rb
brief-1.8.2 lib/brief/cli/init.rb
brief-1.8.1 lib/brief/cli/init.rb
brief-1.8.0 lib/brief/cli/init.rb
brief-1.7.3 lib/brief/cli/init.rb
brief-1.7.2 lib/brief/cli/init.rb
brief-1.7.1 lib/brief/cli/init.rb
brief-1.7.0 lib/brief/cli/init.rb
brief-1.6.1 lib/brief/cli/init.rb
brief-1.6.0 lib/brief/cli/init.rb
brief-1.5.2 lib/brief/cli/init.rb
brief-1.5.1 lib/brief/cli/init.rb
brief-1.5.0 lib/brief/cli/init.rb
brief-1.4.4 lib/brief/cli/init.rb
brief-1.4.2 lib/brief/cli/init.rb
brief-1.4.1 lib/brief/cli/init.rb
brief-1.3.2 lib/brief/cli/init.rb