lib/runeblog.rb in runeblog-0.0.20 vs lib/runeblog.rb in runeblog-0.0.21

- old
+ new

@@ -1,7 +1,8 @@ + class RuneBlog - VERSION = "0.0.20" + VERSION = "0.0.21" Path = File.expand_path(File.join(File.dirname(__FILE__))) DefaultData = Path + "/../data" BlogHeader = File.read(DefaultData + "/blog_header.html") rescue "not found" @@ -57,15 +58,19 @@ ### new_blog! def new_blog! unless File.exist?(".blog") - yn = ask(red(" No .blog found. Create new blog?")) + yn = ask(red(" No .blog found. Create new blog? ")) if yn.upcase == "Y" #-- what if data already exists? system("cp -r #{RuneBlog::DefaultData} .") - File.open(".blog", "w") {|f| f.puts "data" } + File.open(".blog", "w") do |f| + f.puts "data" + f.puts "no_default" + end + system("echo Created #{Time.now} >>data/VERSION") end end end ### next_sequence @@ -85,41 +90,37 @@ end ### read_config def read_config + cfg_file = ".blog" @config = OpenStruct.new # What views are there? Deployment, etc. # Crude - FIXME later - root = File.readlines(".blog").first.chomp rescue "myblog" + new_blog! unless File.exist?(cfg_file) + + lines = File.readlines(cfg_file).map {|x| x.chomp } + root = lines[0] + @view ||= lines[1] dirs = Dir.entries("#{root}/views/") - %w[. ..] dirs.reject! {|x| ! File.directory?("#{root}/views/#{x}") } @config.root = root @config.views = dirs @config.sequence = File.read(root + "/sequence").to_i -rescue => err - if root != "myblog" - raise err - end - - new_blog! - STDERR.puts "Created. Now run again." - exit end ### create_empty_post def create_empty_post @template = <<-EOS .mixin liveblog .liveblog_version -.title #{@title} -.pubdate #{@date} -.categories elixir ruby -.views computing +.title #@title +.pubdate #@date +.views #@view Teaser goes here. .readmore Remainder of post goes here. EOS @@ -138,23 +139,25 @@ ### process_post def process_post(file) @main ||= Livetext.new + @main.main.output = File.new("/tmp/WHOA","w") puts " Processing: #{Dir.pwd} :: #{file}" - path = @config.root + "/src/#{file}" - @meta = @main.process_file(file) +path = @config.root + "/src/#{file}" + @meta = @main.process_file(path) @meta.slug = make_slug(@meta.title, @config.sequence) @meta.slug = file.sub(/.lt3$/, "") @meta end ### reload_post def reload_post(file) @main ||= Livetext.new - @meta = process_post("#{@config.root}/src/#{file}") + @main.main.output = File.new("/tmp/WHOA","w") + @meta = process_post(file) @meta.slug = file.sub(/.lt3$/, "") @meta end ### posting @@ -194,14 +197,16 @@ end ### link_post_view def link_post_view(view) - p @meta # Create dir using slug (index.html, metadata?) vdir = "#{@config.root}/views/#{view}" +p "vdir = #{vdir}" dir = "#{vdir}/#{@meta.slug}" +p "dir = #{dir}" +p "cwd = #{Dir.pwd}" cmd = "mkdir -p #{dir}" #-- FIXME what if this exists?? puts " Running: #{cmd}" system(cmd) File.write("#{dir}/metadata.yaml", @meta.to_yaml) # Add header/trailer to post index @@ -326,10 +331,11 @@ @today = Time.now.strftime("%Y%m%d") @date = Time.now.strftime("%Y-%m-%d") file = create_empty_post edit_post(file) - process_post(file) +# file = @config.root + "/src/" + file + process_post(file) #- FIXME handle each view if publish? link_post(@meta) publish_post end end