# HG changeset patch
# User yuuji@gentei.org
# Date 1278509245 -32400
# Node ID b7b54906ac3b217c1c07778a466cb5bce00d7fa0
# Parent 7919fbbb33c00d928de4c3aa0c745cb694c4c94e
add newpage.rb
diff -r 7919fbbb33c0 -r b7b54906ac3b newpage.rb
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/newpage.rb Wed Jul 07 22:27:25 2010 +0900
@@ -0,0 +1,124 @@
+#!/usr/bin/env ruby
+# THIS is very very tentative. Insufficient examination of function.
+# Create new HTML file referring other HTML file in the same directory.
+# Example:
+# newpage.rb Create new index.html by copying template.
+# newpage.rb foo.html Create new foo.html whose by copying header
+# and footer from index.html.
+# newpage.rb d/sub.html Create new directory d (if necessary) and
+# d/sub.html by copying header/footer from
+# index.html in a same directory or parent
+# directory rewriting href to css file
+# considering relative path.
+# newpage.rb -o [file] Forcibly overwrite existing file.
+# newpage.rb -c cssfile Set `cssfile' as defualt css.
+# newpage.rb -t template Set `template' as HTML template.
+require 'fileutils'
+
+mydir=File.dirname($0)
+myname=File.basename($0, ".rb")
+
+
+index = 'index.html'
+cssdefault = nil
+overwrite = nil
+template = __FILE__ #File.expand_path(myname+".html", mydir)
+
+def guesscss(dir)
+
+end
+
+while ARGV[0] && /^-/ =~ (a0=ARGV[0].dup) && ARGV.shift
+ break if /^--$/ =~ a0
+ while /^-[A-Za-z]/ =~ a0
+ case a0
+ when "-c" # css
+ ARGV.shift; cssdefault = ARGV[0]
+ when "-t" # template
+ ARGV.shift; cssdefault = ARGV[0]
+ when "-o" # overwrite
+ overwrite = true
+ end
+ a0.sub!(/-.(.*)/, '-\\1')
+ end
+end
+
+outfile = ARGV[0]||index
+if !overwrite && test(?s, outfile) then
+ STDERR.printf("File \`%s' exists. Use -o option to overwrite.\n", outfile)
+ exit 1
+end
+
+# set css default file
+dots = 0
+of = outfile
+dots+=1 while "." != (of=File.dirname(of))
+cssdir = "../"*dots
+
+# set copy source
+outdir = File.dirname(outfile)
+if "index.html" == File.basename(outfile)
+ src = (dots == 0 ? template : "index.html")
+elsif test(?s, outdir+"/index.html")
+ src = outdir+"/index.html"
+else
+ src = template
+end
+
+FileUtils.mkdir_p(outdir)
+
+cssfile = cssdir+"main.css"
+name = File.basename(outfile, ".html")
+begin
+ open(outfile, "w") do |out|
+ #IO.foreach(src) do |line|
+ if src == __FILE__
+ input = DATA
+ else
+ input = open(src, "r")
+ end
+ begin
+ html = input.readlines.join
+ html.sub!(%r|^
|i, sprintf("%s
\n", name))
+ if !html.gsub!("__CSSFILE__", cssfile)
+ html.gsub!(/href=(['\"])(.*\.css)\1/, 'href="\1"')
+ end
+ html.gsub!("__TITLE__", name)
+ out.print html
+ ensure
+ input.close
+ end
+ end
+ printf(<<_EOS_, outfile, name)
+%s
+_EOS_
+rescue
+ p $!
+ STDERR.printf(<<'_EOS_', outfile, outfile)
+Cannot output to [%s]. Do
+ chmod +w %s
+or
+ chmod +w .
+or change output directory.
+_EOS_
+ exit 1
+end
+
+__END__
+
+
+__TITLE__
+
+
+
+
+
+__TITLE__
+
+
+
+
diff -r 7919fbbb33c0 -r b7b54906ac3b yahtml.el
--- a/yahtml.el Thu Jun 24 16:01:45 2010 +0900
+++ b/yahtml.el Wed Jul 07 22:27:25 2010 +0900
@@ -1,6 +1,6 @@
;;; -*- Emacs-Lisp -*-
;;; (c) 1994-2010 by HIROSE Yuuji [yuuji(@)yatex.org]
-;;; Last modified Thu Jun 24 16:00:42 2010 on firestorm
+;;; Last modified Wed Jul 7 22:12:55 2010 on firestorm
;;; $Id$
(defconst yahtml-revision-number "1.74.2"
@@ -880,6 +880,25 @@
"class(or class list delimited by \\[quoted-insert] SPC): "))
nil YaTeX-minibuffer-completion-map nil)))
+(defvar yahtml-newpage-command "newpage.rb"
+ "*Command name to create new HTML file referring to index.html.
+This command should create new HTML file named argument 1 and
+output string like `anchor tag'.
+This program should take -o option to overwrite existing HTML file.")
+(defun yahtml-newpage (file ov)
+ "Create newpage via newpage script"
+ (interactive
+ (list
+ (let (insert-default-directory)
+ (read-file-name "New webpage file name: " ""))
+ current-prefix-arg))
+ (if (and (file-exists-p file) (not ov))
+ (error "%s already exists. Call this with universal argument to force overwrite." file))
+ (insert (substring
+ (YaTeX-command-to-string
+ (concat yahtml-newpage-command " " (if ov "-o ") file))
+ 0 -1)))
+
;;; ---------- Add-in ----------
(defun yahtml-addin (form)
"Check add-in function's existence and call it if exists."
@@ -2463,9 +2482,9 @@
;;; ---------- Lint and Browsing ----------
;;;
(defun yahtml-browse-menu ()
- "Browsing menu"
+ "Browsing or other external process invokation menu."
(interactive)
- (message "J)weblint p)Browse R)eload...")
+ (message "J)weblint p)Browse R)eload N)ewpage...")
(let ((c (char-to-string (read-char))))
(cond
((string-match "j" c)
@@ -2473,7 +2492,9 @@
((string-match "[bp]" c)
(yahtml-browse-current-file))
((string-match "r" c)
- (yahtml-browse-reload)))))
+ (yahtml-browse-reload))
+ ((string-match "n" c)
+ (call-interactively 'yahtml-newpage)))))
(if (fboundp 'wrap-function-to-control-ime)
(wrap-function-to-control-ime 'yahtml-browse-menu t nil))
diff -r 7919fbbb33c0 -r b7b54906ac3b yatexlib.el
--- a/yatexlib.el Thu Jun 24 16:01:45 2010 +0900
+++ b/yatexlib.el Wed Jul 07 22:27:25 2010 +0900
@@ -2,7 +2,7 @@
;;; YaTeX and yahtml common libraries, general functions and definitions
;;; yatexlib.el
;;; (c)1994-2009 by HIROSE Yuuji.[yuuji@yatex.org]
-;;; Last modified Thu May 27 15:09:44 2010 on firestorm
+;;; Last modified Wed Jul 7 06:48:48 2010 on firestorm
;;; $Id$
;; General variables
@@ -822,6 +822,21 @@
(win-switch-to-window 1 (- last-command-char win:base-key)))
;;;###autoload
+(defun YaTeX-command-to-string (cmd)
+ (if (fboundp 'shell-command-to-string)
+ (funcall 'shell-command-to-string cmd)
+ (let ((tbuf " *tmpout*"))
+ (if (get-buffer-create tbuf) (kill-buffer tbuf))
+ (let ((standard-output (get-buffer-create tbuf)))
+ (unwind-protect
+ (save-excursion
+ (call-process
+ shell-file-name nil tbuf nil YaTeX-shell-command-option cmd)
+ (set-buffer tbuf)
+ (buffer-string))
+ (kill-buffer tbuf))))))
+
+;;;###autoload
(defun YaTeX-reindent (col)
"Remove current indentation and reindento to COL column."
(save-excursion