Sha256: 6c9d9c24100f83a43a46279e889bdbef9eca20addf97a507a2ea065cb645ca59
Contents?: true
Size: 1.49 KB
Versions: 3
Compression:
Stored size: 1.49 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
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
brief-1.2.0 | lib/brief/cli/init.rb |
brief-1.1.0 | lib/brief/cli/init.rb |
brief-1.0.0 | lib/brief/cli/init.rb |