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, top_dir = '.') ⇒ 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
134 135 136 |
# File 'lib/soupcms/soupcms_cli.rb', line 134 def self.source_root File.join(File.dirname(__FILE__), '../..') end |
Instance Method Details
#clean(name) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/soupcms/soupcms_cli.rb', line 102 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
92 93 94 95 96 97 98 99 |
# File 'lib/soupcms/soupcms_cli.rb', line 92 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
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 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/soupcms/soupcms_cli.rb', line 20 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) if yes?('Would you like to host your website public on platform like Heroku? (y/n):', :cyan) configs[:site_name] = ask('Provide the hostname for your website (e.g. http://myblog.herokuapp.com OR http://www.myblog.com) :', :green) end configs[:blog] = yes?('Blog support? (y/n):', :cyan) 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 top_dir = .skip_dir? ? '.' : name data_folder = "#{top_dir}/data/#{name}" if configs[:blog] template 'lib/templates/pages/post.yml',"#{data_folder}/pages/post.yml" template 'lib/templates/pages/posts.yml',"#{data_folder}/pages/posts.yml" end copy_file 'lib/templates/public/favicon.png', "#{top_dir}/public/favicon.png" copy_file 'lib/templates/public/favicon.ico', "#{top_dir}/public/favicon.ico" copy_file 'lib/templates/public/common/stylesheets/_custom-variables.scss', "#{top_dir}/public/common/stylesheets/_custom-variables.scss" template 'lib/templates/schemaless/footer.yml',"#{data_folder}/schemaless/footer.yml" template 'lib/templates/schemaless/navigation.yml',"#{data_folder}/schemaless/navigation.yml" template 'lib/templates/schemaless/author.yml',"#{data_folder}/schemaless/author.yml" template 'lib/templates/modules/author.yml',"#{data_folder}/modules/author.yml" template 'lib/templates/modules/navigation.yml',"#{data_folder}/modules/navigation.yml" template 'lib/templates/modules/projects.yml',"#{data_folder}/modules/projects.yml" template 'lib/templates/modules/tag-cloud.yml',"#{data_folder}/modules/tag-cloud.yml" template 'lib/templates/modules/share-this.yml',"#{data_folder}/modules/share-this.yml" template 'lib/templates/pages/default.yml',"#{data_folder}/pages/default.yml" template 'lib/templates/pages/home.yml',"#{data_folder}/pages/home.yml" template 'lib/templates/pages/about.md',"#{data_folder}/pages/about.md" template 'lib/templates/Gemfile', "#{top_dir}/Gemfile" template 'lib/templates/Procfile', "#{top_dir}/Procfile" template 'lib/templates/.gitignore', "#{top_dir}/.gitignore" template 'lib/templates/single-app-config.ru', "#{top_dir}/config.ru" if configs[:blog] while yes?('Would you like to add blog post? (y/n):', :cyan) post(configs[:name], top_dir) end end create_file "#{top_dir}/data/#{name}/_config.yml", YAML.dump(JSON.parse(configs.to_json)) end |
#post(name, top_dir = '.') ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/soupcms/soupcms_cli.rb', line 78 def post(name, top_dir = '.') configs[:name] = name configs[:title] = ask('Title for the new post? (20 to 30 char) :', :green) sanitize_title = sanatize(configs[:title]) configs[:sanitize_title] = sanitize_title = ask('Tags as comma separated list:', :green) configs[:tags] = .split(',') template 'lib/templates/blog/my-first-post.md',"#{top_dir}/data/#{name}/posts/#{sanitize_title}.md" copy_file 'lib/templates/public/blog/posts/images/my-first-post.png',"#{top_dir}/public/#{name}/posts/images/#{sanitize_title}.png" copy_file 'lib/templates/public/blog/posts/images/my-first-post/1-post-image.png',"#{top_dir}/public/#{name}/posts/images/#{sanitize_title}/1-post-image.png" end |
#seed(name) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/soupcms/soupcms_cli.rb', line 118 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.} (#{e.class})", :red say "#{e.backtrace.drop(1).map{|s| s }.join("\n")}", :red end end end end |