bin/atom-client.rb in atom-tools-0.9.3 vs bin/atom-client.rb in atom-tools-0.9.4
- old
+ new
@@ -30,11 +30,10 @@
require "atom/yaml"
require "atom/service"
require "atom/http"
require "rubygems"
-require "bluecloth"
require "time"
require 'yaml'
@@ -61,38 +60,30 @@
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)
- # human readability
+ # delete bits the person doesn't need to see
yaml.delete "id"
if yaml["links"]
- yaml["links"].find_all { |l| l["rel"] == "alternate" or l["rel"] == "edit" }.each { |l| yaml["links"].delete(l) }
+ yaml["links"].find_all { |l| ["alternate", "edit"].member? l["rel"] }.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
@@ -143,11 +134,16 @@
yaml = YAML.load(edited)
entry = Atom::Entry.from_yaml yaml
- entry.prepare_for_output
+ if yaml["content"] #and not yaml["type"]
+ entry.content, type = $text_filter_after.call(yaml["content"])
+ entry.content["type"] = (type || "text")
+ end
+
+ entry.updated!
# XXX disabled until the APP WG can decide what a valid entry is
=begin
valid, message = entry.valid?
unless valid
@@ -185,9 +181,17 @@
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|