Class: Adocsite::Commands
- Inherits:
-
Object
- Object
- Adocsite::Commands
- Defined in:
- lib/adocsite/commands.rb
Class Method Summary collapse
- .build(args, options) ⇒ Object
- .dump(args, options) ⇒ Object
- .list(args, options) ⇒ Object
- .load_config(args, options) ⇒ Object
- .load_config_wp(args, options) ⇒ Object
- .post(args, options) ⇒ Object
Class Method Details
.build(args, options) ⇒ Object
3 4 5 6 7 8 |
# File 'lib/adocsite/commands.rb', line 3 def Commands.build(args, ) Commands.load_config(args, ) engine = Adocsite::Engine.new engine.build(.layout) end |
.dump(args, options) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/adocsite/commands.rb', line 10 def Commands.dump(args, ) # default template FileUtils.cp_r(Adocsite.config[:TEMPLATES_FOLDER], "adocsite_default_templates") # default configuration conf = <<-EOS # Default configuration for Adocsite Adocsite::config = #{Adocsite.config.pretty_inspect} EOS File.open("adocsite_default_config.rb", 'w') {|f| f.write(conf) } # example of custom configuration file sample_custom_config = File.join(File.dirname(__FILE__), "..", "..", "examples", "myconfig.rb") FileUtils.cp(sample_custom_config, "adocsite_custom_config_sample.rb") # example of custom wp configuration file sample_custom_config = File.join(File.dirname(__FILE__), "..", "..", "examples", "mywpconfig.rb") FileUtils.cp(sample_custom_config, "adocsite_wp_config_sample.rb") end |
.list(args, options) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/adocsite/commands.rb', line 54 def Commands.list(args, ) Commands.load_config(args, ) alist = Hash.new engine = Adocsite::Engine.new engine.content_loader.articles.collect{|key, article| alist[key] = article.title} atable = [] alist.each_pair {|key, value| atable << [key.to_str, value] } puts Terminal::Table.new :headings => ['name', 'title'], :rows => atable puts 'Done.' end |
.load_config(args, options) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/adocsite/commands.rb', line 70 def Commands.load_config(args, ) user_config_file_name = .config || "adocsite_config.rb" user_config_file = File.join(Dir.pwd, user_config_file_name) if File.exists?(user_config_file) require user_config_file else user_config_file = File.join(Dir.home, ".adocsite") if File.exists?(user_config_file) require user_config_file end end end |
.load_config_wp(args, options) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/adocsite/commands.rb', line 83 def Commands.load_config_wp(args, ) user_config_file_name = .config || "adocsite_wp_config.rb" user_config_file = File.join(Dir.pwd, user_config_file_name) if File.exists?(user_config_file) require user_config_file else user_config_file = File.join(Dir.home, ".adocsite_wp") if File.exists?(user_config_file) require user_config_file end end end |
.post(args, options) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/adocsite/commands.rb', line 32 def Commands.post(args, ) Commands.load_config_wp(args, ) wp = Adocsite::WpPost.new if .list alist = wp.list_articles atable = [] alist.each_pair {|key, value| atable << [key.to_str, value] } puts Terminal::Table.new :headings => ['name', 'title'], :rows => atable elsif .title wp.process_by_title(.title) else article_name = args.shift || abort('Article title is required.') wp.process(article_name) end puts 'Done.' end |