Top Level Namespace
Defined Under Namespace
Classes: RuneCMS
Constant Summary collapse
- CONFIG =
"config.txt"
Instance Method Summary collapse
- #command?(cmd) ⇒ Boolean
- #execute(cmd) ⇒ Object
- #fix_extension(file) ⇒ Object
- #lt3?(file) ⇒ Boolean
- #read_config ⇒ Object
- #run_browse ⇒ Object
- #run_check ⇒ Object
- #run_config ⇒ Object
- #run_generate ⇒ Object
- #run_publish ⇒ Object
- #run_update ⇒ Object
- #run_version ⇒ Object
- #run_view ⇒ Object
-
#stale?(file) ⇒ Boolean
without source/ or target/.
- #stale_files(dir) ⇒ Object
- #update_target(file) ⇒ Object
- #usage_message ⇒ Object
- #verify_dirs ⇒ Object
Instance Method Details
#command?(cmd) ⇒ Boolean
66 67 68 |
# File 'lib/runecms/commands.rb', line 66 def command?(cmd) self.respond_to?("run_#{cmd}", true) end |
#execute(cmd) ⇒ Object
70 71 72 |
# File 'lib/runecms/commands.rb', line 70 def execute(cmd) send("run_#{cmd}") end |
#fix_extension(file) ⇒ Object
71 72 73 74 75 76 77 78 |
# File 'lib/runecms/support.rb', line 71 def fix_extension(file) if lt3?(file) file2 = file.sub(/.lt3$/, ".html") else file2 = file end file2 end |
#lt3?(file) ⇒ Boolean
67 68 69 |
# File 'lib/runecms/support.rb', line 67 def lt3?(file) file.end_with?(".lt3") end |
#read_config ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/runecms/support.rb', line 80 def read_config config = "config.txt" here = Dir.pwd loop do raise if Dir.pwd == "/" # shouldn't get this far break if File.exist?(config) Dir.chdir("..") end lines = File.readlines("config.txt") # Example: "user: hal9000" lines.each do |line| var, val = line.split(": ") instance_variable_set("@" + var, val.chomp.strip) end return true rescue => e puts "Can't read config file: here = #{here} pwd = #{Dir.pwd}" puts e return false end |
#run_browse ⇒ Object
62 63 64 |
# File 'lib/runecms/commands.rb', line 62 def run_browse system("open #@server") end |
#run_check ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/runecms/commands.rb', line 10 def run_check list = stale_files("source") if stale.empty? puts "No stale files" else puts "Stale files:" stale.each {|x| puts " " + x } puts end end |
#run_config ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/runecms/commands.rb', line 21 def run_config unless read_config File.open("config.txt", "w") do |f| f.puts "server: " f.puts "path: " f.puts "user: " end end system("vi config.txt") end |
#run_generate ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/runecms/commands.rb', line 32 def run_generate verify_dirs # handle missing subdirectories list = stale_files("source") if stale.empty? puts "Nothing to do" else puts "Stale files:" stale.each do |file| puts " " + x update_target(file) end puts end end |
#run_publish ⇒ Object
57 58 59 60 |
# File 'lib/runecms/commands.rb', line 57 def run_publish cmd = "rsync -r -z target/ #@user@#@server:#@path/" system(cmd) end |
#run_update ⇒ Object
47 48 49 50 |
# File 'lib/runecms/commands.rb', line 47 def run_update run_generate run_publish end |
#run_version ⇒ Object
6 7 8 |
# File 'lib/runecms/commands.rb', line 6 def run_version puts RuneCMS::VERSION end |
#run_view ⇒ Object
52 53 54 55 |
# File 'lib/runecms/commands.rb', line 52 def run_view # FIXME index is hardcoded... system("open target/index.html") end |
#stale?(file) ⇒ Boolean
without source/ or target/
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/runecms/support.rb', line 26 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 |
#stale_files(dir) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/runecms/support.rb', line 17 def stale_files(dir) list = nil path = "#{Dir.pwd}/#{dir}/" list = Find.find(path).to_a list = list.select {|x| ! File.directory?(x) } list.map! {|x| x.sub(path, "") } list.select {|x| stale?(x) } end |
#update_target(file) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/runecms/support.rb', line 41 def update_target(file) file2 = fix_extension(file) if lt3?(file) cmd = "livetext source/#{file} > target/#{file2}" else if File.directory?(file) cmd = "mkdir target/#{file2}" else cmd = "cp source/#{file} target/#{file2}" end end system(cmd) end |
#usage_message ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/runecms/support.rb', line 2 def puts puts " rcms config Initialize config.txt if necessary and edit with vi\n rcms check List stale files, but do nothing else\n rcms generate Find stale files under source/ and generate them under target/\n rcms view View the current state of target/ via browser (local files)\n rcms publish Publish target/ to the remote server\n rcms update Shortcut - Like a generate followed by a push\n rcms browse Browse the current state of the remote server\n TEXT\n puts\n exit\nend\n" |
#verify_dirs ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/runecms/support.rb', line 55 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 |