Class: Meta::CLI
Instance Method Summary collapse
- #capture(url) ⇒ Object
- #compile ⇒ Object
- #init ⇒ Object
- #stage ⇒ Object
- #test ⇒ Object
- #title(file) ⇒ Object
Instance Method Details
#capture(url) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/meta/cli.rb', line 104 def capture(url) if [:output].nil? dest = BASEDIR else dest = [:output] end images = dest + SLASH + "images" images = dest unless Dir.exists?(images) cmd = "xvfb-run url2thumb capture #{url} -o #{images}" stdin, stdout, stderr = Open3.popen3(cmd) abort( stderr.read.chomp.red ) if stdout.nil? out = stdout.read.chomp unless out.include?(FEXISTS) created = out.split(SPACE).first link = "[})](#{url})" Meta::Filelib.create_file( link, created, MDEXT, dest, false ) end end |
#compile ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/meta/cli.rb', line 15 def compile if [:output].nil? dest = "." else dest = [:output] end p = Meta::Page.new(dest) p.generate([:force]) p.generate_index([:force]) end |
#init ⇒ Object
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 |
# File 'lib/meta/cli.rb', line 31 def init f = File.join( File.dirname(__FILE__), "../../db/site.sqlite3" ) if File.exists?("site.sqlite3") puts "Warning: All index data will be lost!".red reply = agree("Database already exists, overwrite?".red) { |q| q.default = "n" } if reply FileUtils.cp( f, Dir.pwd ) puts "Database re-initialized".green else puts "Database not initialized".red end else FileUtils.cp( f, Dir.pwd ) puts "Database initialized".green end end |
#stage ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/meta/cli.rb', line 58 def stage config = File.join( File.dirname(__FILE__), "../../config/config.ru" ) if File.exists?("config.ru") puts "Environment has already been staged, no action taken.".yellow else FileUtils.cp( config, Dir.pwd ) puts "Run 'rackup' to start testing.".green end end |
#test ⇒ Object
137 138 139 140 141 142 143 144 |
# File 'lib/meta/cli.rb', line 137 def test c = Meta::Catalog.new stats = c.get_statistics puts stats[:posts] puts stats[:pictures] end |
#title(file) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/meta/cli.rb', line 74 def title(file) catalog = Meta::Catalog.new f = catalog.get_content(file) unless f.nil? puts "Current Title: #{f[:title]}" reply = ask "New Title? ".yellow unless reply.empty? response = agree( "Are you certain that you want to make this change? ") { |q| q.default = "n" } catalog.update_content_title( file, reply ) if response else puts "Title cannot be empty, no action taken.".red end end end |