Class: SoupCMSCLI
- Inherits:
-
Thor
- Object
- Thor
- SoupCMSCLI
- Includes:
- Thor::Actions
- Defined in:
- lib/soupcms/soupcms_cli.rb
Instance Attribute Summary collapse
-
#configs ⇒ Object
readonly
Returns the value of attribute configs.
Class Method Summary collapse
Instance Method Summary collapse
- #clean(name) ⇒ Object
- #delete(name) ⇒ Object
-
#initialize(*args) ⇒ SoupCMSCLI
constructor
A new instance of SoupCMSCLI.
- #new(name) ⇒ Object
- #post(name) ⇒ Object
- #seed(name) ⇒ Object
Constructor Details
#initialize(*args) ⇒ SoupCMSCLI
Returns a new instance of SoupCMSCLI.
10 11 12 13 |
# File 'lib/soupcms/soupcms_cli.rb', line 10 def initialize(*args) super @configs = {} end |
Instance Attribute Details
#configs ⇒ Object (readonly)
Returns the value of attribute configs.
15 16 17 |
# File 'lib/soupcms/soupcms_cli.rb', line 15 def configs @configs end |
Class Method Details
.source_root ⇒ Object
122 123 124 |
# File 'lib/soupcms/soupcms_cli.rb', line 122 def self.source_root File.join(File.dirname(__FILE__), '../..') end |
Instance Method Details
#clean(name) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/soupcms/soupcms_cli.rb', line 90 def clean(name) mongo_uri = ENV["MONGODB_URI_#{name}"] || "mongodb://localhost:27017/#{name}" conn = Mongo::MongoClient.from_uri(mongo_uri) db = conn.db say "Cleaning up the database '#{name}'", :green db.collection_names.each { |coll_name| next if coll_name.match(/^system/) say "Dropping collection '#{coll_name}'", :red db.drop_collection(coll_name) } conn.close end |
#delete(name) ⇒ Object
80 81 82 83 84 85 86 87 |
# File 'lib/soupcms/soupcms_cli.rb', line 80 def delete(name) if yes?("Are you sure you would like to delete #{name}? (y/n):") remove_dir "data/#{name}" remove_dir "public/#{name}" remove_file 'Procfile' remove_file 'config.ru' end end |
#new(name) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/soupcms/soupcms_cli.rb', line 19 def new(name) configs[:name] = name configs[:display_name] = ask('Short display application name? (10 to 15 char) :', :green) configs[:description] = ask('Long application description? (30 to 40 char) :', :green) configs[:blog] = yes?('Blog support? (y/n):', :blue) if configs[:blog] say('Choose blog layout? (y/n):',:green) blog_layouts = [[1, 'full-width'], [2, 'right-sidebar'], [3, 'left-sidebar']] print_table blog_layouts layout = ask('choose from', :green, :limited_to => %w(1 2 3)) configs[:blog_layout] = blog_layouts[layout.to_i - 1][1] end if configs[:blog] template 'lib/templates/pages/blog-post.yml',"data/#{name}/pages/blog-post.yml" template 'lib/templates/pages/posts.yml',"data/#{name}/pages/posts.yml" end copy_file 'lib/templates/public/favicon.png', 'public/favicon.png' template 'lib/templates/schemaless/footer.yml',"data/#{name}/schemaless/footer.yml" template 'lib/templates/schemaless/navigation.yml',"data/#{name}/schemaless/navigation.yml" template 'lib/templates/schemaless/social-toolbar.yml',"data/#{name}/schemaless/social-toolbar.yml" template 'lib/templates/pages/default.yml',"data/#{name}/pages/default.yml" template 'lib/templates/pages/home.yml',"data/#{name}/pages/home.yml" template 'lib/templates/pages/about.md',"data/#{name}/pages/about.md" template 'lib/templates/Gemfile', 'Gemfile' template 'lib/templates/Procfile', 'Procfile' if yes?('Would you like to host your website public on platform like Heroku? (y/n):', :blue) configs[:site_name] = ask('Provide the hostname for your website (e.g. http://myblog.herokuapp.com OR http://www.myblog.com) :', :green) end template 'lib/templates/single-app-config.ru', 'config.ru' if configs[:blog] while yes?('Would you like to add blog post? (y/n):', :blue) post(configs[:name]) end end create_file "data/#{name}/_config.yml", YAML.dump(JSON.parse(configs.to_json)) end |
#post(name) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/soupcms/soupcms_cli.rb', line 66 def post(name) configs[:name] = name configs[:title] = ask('Title for the new post? (20 to 30 char) :', :green) sanitize_title = configs[:title].gsub(' ','-').gsub('\'','').gsub(',','').downcase #TODO: proper sanitization configs[:sanitize_title] = sanitize_title = ask('Tags as comma separated list:', :green) configs[:tags] = .split(',') template 'lib/templates/blog/my-first-post.md',"data/#{name}/posts/#{sanitize_title}.md" copy_file 'lib/templates/public/blog/posts/images/my-first-post.png',"public/#{name}/posts/images/#{sanitize_title}.png" copy_file 'lib/templates/public/blog/posts/images/my-first-post/1-post-image.png',"public/#{name}/posts/images/#{sanitize_title}/1-post-image.png" end |
#seed(name) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/soupcms/soupcms_cli.rb', line 106 def seed(name) clean(name) if .clean? ENV['verbose'] = .verbose?.to_s Dir.glob("data/#{name}/**/*.{json,md,yml}").each do |file| unless file.include?('ref_files') || file.include?('_config.yml') begin SoupCMS::CLI::Model::Base.create_model(File.new(file)) rescue => e say "Error importing file... #{file}", :red say "#{e.backtrace.first}: #{e.message} (#{e.class})", :red say "#{e.backtrace.drop(1).map{|s| s }.join("\n")}", :red end end end end |