Permalink
Browse files

now able to convert org-strings to html

  • Loading branch information...
1 parent 8a034c9 commit 30e3e13f7e91d54420363ee783ce6da8e37d1779 @eschulte committed Feb 1, 2009
Showing with 61 additions and 16 deletions.
  1. +5 −2 README.markdown
  2. +16 −1 elisp/org-interaction.el
  3. +2 −0 init.rb
  4. +38 −13 lib/acts_as_org.rb
View
@@ -5,8 +5,11 @@ shouldn't be used
ActsAsOrg
==========
-Provides org-mode actions for ActiveFile records. See the following
-for information on the relevant resources.
+Provides org-mode actions for ActiveFile records. Org-mode is a
+plain-text format for "keeping notes, maintaining ToDo lists, doing
+project planning, and authoring" html, LaTeX, and Sweave documents.
+For more information on org-mode see [Org-Mode](http://orgmode.org/).
+See the following for information on the relevant resources.
- ActiveFile (from [github](http://github.com/eschulte/active_file/tree/master))
- Emacs (22 or later)
View
@@ -32,11 +32,26 @@ html as a string."
(nth 5 (file-attributes file-path))))))
html-path
(with-temp-filebuffer
- file-path
+ file-path
+ (org-mode)
(save-window-excursion
(org-export-as-html-to-buffer nil)
(write-file html-path)
(kill-buffer))))))
+;; ;; probably not going to use this since passing complicated string
+;; ;; to emacs on the command line is very iffy
+;; (defun org-string-to-html (org-string)
+;; "Convert ORG-STRING to html as if it was an `org-mode'
+;; document, then return the html as a string."
+;; (let* ((file-path (make-temp-file "org-string"))
+;; (file-name (make-temp-file "org-string"))
+;; (file-dir (file-name-directory file-path))
+;; (html-path (expand-file-name (concat org-interaction-prefix file-name) file-dir)))
+;; (org-file-to-html file-name)
+;; (with-temp-buffer
+;; (insert-file-contents html-path)
+;; (read-buffer))))
+
;; customization
(setq org-export-blocks-witheld '(hidden comment))
View
@@ -1,3 +1,5 @@
require 'active_file'
require 'acts_as_org'
ActiveFile::Base.send(:include, ActiveFile::Acts::Org)
+
+## maybe something here to start up an emacs-client
View
@@ -1,6 +1,9 @@
module ActiveFile
module Acts
module Org
+ # *note*: if you change this value, you must also change the
+ # value of `org-interaction-prefix' in
+ # ../elisp/org-interaction.el
EXP_PREFIX = ".exported_"
def self.included(base)
@@ -16,23 +19,26 @@ def acts_as_org(options={})
def emacs_run(command)
%x{emacs -Q -batch -l #{File.join(File.dirname(__FILE__), "..", "elisp", "org-interaction.el")} -eval '#{command}'}
end
- end
-
- module InstanceMethods
- def html_path
- File.join(File.dirname(self.full_path),
- ActiveFile::Acts::Org::EXP_PREFIX + File.basename(self.path))
+
+ # convert a string of org-formatted text to html
+ def string_to_html(org_string, options = {})
+ tmp = Tempfile.new("org-string")
+ tmp << org_string
+ tmp.flush
+ self.to_html(tmp.path, options)
end
- def clean_html?
- File.exist?(self.html_path) and File.mtime(self.html_path) > File.mtime(self.full_path)
+ def html_path(path)
+ File.join(File.dirname(path),
+ ActiveFile::Acts::Org::EXP_PREFIX + File.basename(path))
end
-
- def to_html(options = {})
+
+ def to_html(path, options = {})
+ h_path = self.html_path(path)
options = {:postamble => false}.merge(options)
- self.class.emacs_run "(org-file-to-html \"#{self.full_path}\")" unless self.clean_html?
- return nil unless File.exist?(self.html_path)
- html = File.read(self.html_path)
+ self.emacs_run("(org-file-to-html \"#{path}\")") unless self.clean_html?(path)
+ return nil unless File.exist?(h_path)
+ html = File.read(h_path)
# extract the body portion
start_body = (html =~ /<body>/) + 6
end_body = (html =~ /<\/body>/) - 1
@@ -43,6 +49,25 @@ def to_html(options = {})
body[(0..(body.index("<div id=\"postamble\">") - 1))]
end
end
+
+ def clean_html?(path)
+ h_path = self.html_path(path)
+ File.exist?(h_path) and File.mtime(h_path) > File.mtime(path)
+ end
+ end
+
+ module InstanceMethods
+ def html_path
+ self.class.html_path(self.full_path)
+ end
+
+ def clean_html?
+ self.class.clean_html?(self.full_path)
+ end
+
+ def to_html(options = {})
+ self.class.to_html(self.full_path, options)
+ end
end
end
end

0 comments on commit 30e3e13

Please sign in to comment.