bin/atom-client.rb in atom-tools-0.9.4 vs bin/atom-client.rb in atom-tools-1.0.0
- old
+ new
@@ -30,10 +30,11 @@
require "atom/yaml"
require "atom/service"
require "atom/http"
require "rubygems"
+require "bluecloth"
require "time"
require 'yaml'
@@ -60,30 +61,38 @@
ret
end
end
class Atom::Entry
+ def prepare_for_output
+ filter_hook
+
+ updated!
+ end
+
+ def filter_hook
+ # so much for actual text content...
+ if @content and @content["type"] == "text"
+ self.content = BlueCloth.new( @content.to_s ).to_html
+ @content["type"] = "xhtml"
+ end
+ end
+
def edit
yaml = YAML.load(self.to_yaml)
- # delete bits the person doesn't need to see
+ # human readability
yaml.delete "id"
if yaml["links"]
- yaml["links"].find_all { |l| ["alternate", "edit"].member? l["rel"] }.each { |l| yaml["links"].delete(l) }
+ yaml["links"].find_all { |l| l["rel"] == "alternate" or l["rel"] == "edit" }.each { |l| yaml["links"].delete(l) }
yaml.delete("links") if yaml["links"].empty?
end
-
- if self.content
- yaml["content"] = $text_filter_before.call(self.content.html)
- end
-
+
new_yaml, entry = write_entry(yaml.to_yaml)
- # restore deleted bits
entry.id = self.id
- self.links.each { |l| entry.links << l }
[new_yaml["slug"], entry]
end
end
@@ -134,16 +143,11 @@
yaml = YAML.load(edited)
entry = Atom::Entry.from_yaml yaml
- if yaml["content"] #and not yaml["type"]
- entry.content, type = $text_filter_after.call(yaml["content"])
- entry.content["type"] = (type || "text")
- end
-
- entry.updated!
+ entry.prepare_for_output
# XXX disabled until the APP WG can decide what a valid entry is
=begin
valid, message = entry.valid?
unless valid
@@ -181,17 +185,9 @@
url = if options[:url]
options[:url]
else
yaml = YAML.load(File.read("#{ENV["HOME"]}/.atom-client"))
-
- # leave it the way it came in
- i = Proc.new { |x| x }
- $text_filter_before = eval(yaml["text_filter_before"])
- $text_filter_before ||= i
- $text_filter_after = eval(yaml["text_filter_after"])
- $text_filter_after ||= i
-
collections = yaml["collections"]
puts "which collection?"
collections.keys.each_with_index do |name,index|