Top Level Namespace
Defined Under Namespace
Classes: RuneCMS
Constant Summary collapse
- CONFIG =
"config.txt"
Instance Method Summary collapse
- #command?(cmd) ⇒ Boolean
- #execute(cmd) ⇒ Object
- #find_files(dir) ⇒ Object
- #fix_extension(file) ⇒ Object
- #lt3?(file) ⇒ Boolean
- #read_config ⇒ Object
- #run_browse ⇒ Object
- #run_config ⇒ Object
- #run_generate ⇒ Object
- #run_publish ⇒ Object
- #run_update ⇒ Object
- #run_view ⇒ Object
-
#stale?(file) ⇒ Boolean
without source/ or target/.
- #update_target(file) ⇒ Object
- #usage_message ⇒ Object
- #verify_dirs ⇒ Object
Instance Method Details
#command?(cmd) ⇒ Boolean
52 53 54 |
# File 'lib/runecms/commands.rb', line 52 def command?(cmd) self.respond_to?("run_#{cmd}", true) end |
#execute(cmd) ⇒ Object
56 57 58 |
# File 'lib/runecms/commands.rb', line 56 def execute(cmd) send("run_#{cmd}") end |
#find_files(dir) ⇒ Object
16 17 18 19 |
# File 'lib/runecms/support.rb', line 16 def find_files(dir) list = Find.find(dir).to_a - [dir] list.map {|x| x.sub("#{dir}/","") } end |
#fix_extension(file) ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/runecms/support.rb', line 66 def fix_extension(file) if lt3?(file) file2 = file.sub(/.lt3$/, ".html") else file2 = file end file2 end |
#lt3?(file) ⇒ Boolean
62 63 64 |
# File 'lib/runecms/support.rb', line 62 def lt3?(file) file.end_with?(".lt3") end |
#read_config ⇒ Object
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/runecms/support.rb', line 75 def read_config lines = File.readlines("config.txt") # Example: "user: hal9000" lines.each do |line| var, val = line.split(": ") instance_variable_set("@"+var, val.chomp.strip) end rescue => err abort "Can't open config file: #{err}" end |
#run_browse ⇒ Object
46 47 48 49 50 |
# File 'lib/runecms/commands.rb', line 46 def run_browse system("open #@server") # puts "Would run: 'open #@server'" # puts end |
#run_config ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/runecms/commands.rb', line 6 def run_config unless File.exist?(CONFIG) File.open(CONFIG, "w") do |f| f.puts "server: " f.puts "path: " f.puts "user: " end end system("vi #{CONFIG}") end |
#run_generate ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/runecms/commands.rb', line 17 def run_generate verify_dirs # handle missing subdirectories list = find_files("source") list.each do |file| next if File.directory?(file) if stale?(file) puts " #{file} is stale" update_target(file) end end end |
#run_publish ⇒ Object
34 35 36 37 38 39 |
# File 'lib/runecms/commands.rb', line 34 def run_publish cmd = "rsync -r -z target/ #@user@#@server:#@path/" system(cmd) # puts "Would run: '#{cmd}'" # puts end |
#run_update ⇒ Object
41 42 43 44 |
# File 'lib/runecms/commands.rb', line 41 def run_update run_generate run_publish end |
#run_view ⇒ Object
29 30 31 32 |
# File 'lib/runecms/commands.rb', line 29 def run_view # FIXME index is hardcoded... system("open target/index.html") end |
#stale?(file) ⇒ Boolean
without source/ or target/
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/runecms/support.rb', line 21 def stale?(file) # without source/ or target/ return false if File.directory?(file) if file.end_with?(".lt3") file1 = file file2 = file.sub(/.lt3$/, ".html") else file1 = file2 = file end return true if ! File.exist?("target/#{file2}") t1 = File.mtime("source/#{file1}") t2 = File.mtime("target/#{file2}") t1 > t2 end |
#update_target(file) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/runecms/support.rb', line 36 def update_target(file) file2 = fix_extension(file) if lt3?(file) update = "livetext" redir = ">" else update = "cp" redir = "" end cmd = "#{update} source/#{file} #{redir} target/#{file2}" # puts cmd system(cmd) end |
#usage_message ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/runecms/support.rb', line 2 def puts puts <<-TEXT rcms config Initialize config.txt if necessary and edit with vi rcms generate Find stale files under source/ and generate them under target/ rcms view View the current state of target/ via browser (local files) rcms publish Publish target/ to the remote server rcms update Shortcut - Like a generate followed by a push rcms browse Browse the current state of the remote server TEXT puts exit end |
#verify_dirs ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/runecms/support.rb', line 50 def verify_dirs src_dirs = [] Find.find("source") do |path| src_dirs << path if File.directory?(path) end src_dirs.each do |path| tdir = path.sub("source", "target") Dir.mkdir(tdir) unless Dir.exist?(tdir) end end |