Permalink
Browse files

Convert from Amrita to ERB, use system temp dirs

  • Loading branch information...
1 parent 1b95d57 commit 9feeca4ef1647b67915ec64dfc897c1a7178806d Aredridel committed Sep 14, 2010
View
@@ -1,18 +1,23 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 Strict//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
+<!DOCTYPE html>
+<html>
<head>
<!-- <link rel="StyleSheet" href="http://pseudomammal.org/style/platypus-green" />-->
<link rel="StyleSheet" href="/global-site-overlay/ambindextrous/ambindextrous.css" />
- <title>Index of <span amrita:id='path'>/stuff</span></title>
+ <title>Index of <%= path %></title>
</head>
<body>
- <h1>Index of <span amrita:id='path'>/stuff</span></h1>
+ <h1>Index of <%= path %></h1>
<table class="directory">
<tr class="directory"><td class="parent" colspan="3"><a href="../">Parent Directory</a></td></tr>
- <tr class='images' amrita:id='images'><td class='image'><a href="@pathurl"><img src='@thumbnail' title='@path' /></a></td><td class='time' amrita:id='time'>19 Jan 04</td><td><span amrita:id='size'>1.5mb, 800x600</span> <span amrita:id='description'>A nice picture.</span></td></tr>
- <tr class="directory" amrita:id='entries'><td class="file"><a href="@pathurl"><span amrita:id='path'>backgrounds</span><span amrita:id='type'>/</span></a></td><td class="time" amrita:id='time'>19 Jan 04</td><td><span amrita:id='size'>16 files</span> <span amrita:id='description'>Classy up your desktop.</span></td></tr>
+ <% images.each do |entry| %>
+ <tr class='images'><td class='image'><a href="<%= entry.pathurl %>"><img src='<%= entry.thumbnail %>' title='<%= entry.path %>' /></a></td><td class='time'><%= entry.time %></td><td><%= entry.size %> <%= entry.description %></td></tr>
+ <% end %>
+ <% entries.each do |entry| %>
+ <tr class="directory"><td class="file"><a href="<%= entry.pathurl %>"><%= entry.path %><%= entry.type %></a></td><td class="time"><%= entry.time %></td><td><%= entry.size %> <%= entry.description %></td></tr>
+ <% end %>
</table>
-<p amrita:id='description'>Minimally sorted. Explore, please.</p>
+
+ <p><%= description %></p>
<!--
<hr />
View
125 bin/ambindextrous 100644 → 100755
@@ -4,12 +4,12 @@ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
require 'fcgi'
require 'logger'
-require 'amrita/template'
-require 'xattr'
+require 'erb'
require 'digest/md5'
require 'uri'
require 'cgi/pathmap'
require 'cacher/webthumbnailer'
+require 'ostruct'
LOGGER = Logger.new('/dev/null')
@@ -19,17 +19,6 @@ class String
end
end
-class XMLTemplateFile < Amrita::TemplateFile
- def initialize(file)
- super(file)
- self.xml = true
- self.asxml = true
- self.expand_attr = true
- self.amrita_id = 'amrita:id'
- self.use_compiler = true
- end
-end
-
class Integer
def as_filesize
if self > 2**30
@@ -60,7 +49,7 @@ class File
end
end
end
- Amrita::SanitizedString.new [ # FIXME: this escaping is too simplistic
+ [
if dc > 0
"#{dc} #{if dc > 1 then "directories" else "directory" end},"
else
@@ -133,16 +122,16 @@ class Ambindextrous < FCGILet
end
paths = [dir, docroot, File.join(File.dirname(__FILE__), '..')]
files = ['.ambindextrous.html', 'ambindextrous.html']
- templatefile = paths.map { |e| files.map { |f| File.join(e, f) } }.flatten.select { |e| LOGGER.debug("Seeking #{e}."); t = File.exists? e; if t: LOGGER.debug('found'); end; t }.first
+ templatefile = paths.map { |e| files.map { |f| File.join(e, f) } }.flatten.select { |e| LOGGER.debug("Seeking #{e}."); t = File.exists? e; if t then LOGGER.debug('found'); end; t }.first
LOGGER.debug("templatefile = #{templatefile}")
- self.template = XMLTemplateFile.new(templatefile)
+ self.template = ERB.new(File.read(templatefile))
if File.exists?(File.join(docroot, 'ambindextrous-edit.html'))
- self.edittemplate = XMLTemplateFile.new(File.join(docroot, 'ambindextrous-edit.html'))
+ self.edittemplate = ERB.new(File.read(File.join(docroot, 'ambindextrous-edit.html')))
else
- self.edittemplate = XMLTemplateFile.new('ambindextrous-edit.html')
+ self.edittemplate = ERB.new(File.read(File.join(File.dirname($0), '..', 'ambindextrous-edit.html')))
end
- self.do_images = if File.read(templatefile).grep(/amrita:id=.images./): true else false end
+ self.do_images = true
end
def log_errors
@@ -167,48 +156,17 @@ class Ambindextrous < FCGILet
end
end
- def save_feedback
- param_data = self.in.read(self.in.size)
- param_data = param_data.split('&').map {|e| e.split('=')}
- params = Hash.new { |h,k| h[k] = param_data.assoc(k)[1] }
- if params['text']
- File.set_attr(systempath, 'feedback', params['text'].formdecode)
- end
- out << "Status: 302\nLocation: #{path}\n\n"
- end
-
def show_edit
- begin
- data = { :text => File.get_attr(systempath, 'feedback') , :path => path }
- rescue Errno::EOPNOTSUPP => e
- data = { :text => '', :path => path }
- end
- edittemplate.expand out, data
+ text = ''
+ out.puts(edittemplate.result(binding))
end
def show_listing
- data = Hash.new
- data[:path] = path
- data[:images] = []
- data[:entries] = []
-
- begin
- a = File.get_attr systempath, 'feedback'
- rescue Errno::EOPNOTSUPP => e
- a = ''
- rescue Errno::EPERM => e
- a = ''
- end
+ images = []
+ entries = []
- data[:feedback] = Amrita::SanitizedString.new(a.gsub("(.*)\n", '<p>\1</p>')) if a
- begin
- a = File.get_attr systempath, 'description'
- rescue Errno::EOPNOTSUPP => e
- a = ''
- rescue Errno::EPERM => e
- a = ''
- end
- data[:description] = Amrita::SanitizedString.new(a.gsub("\n", "<br />")) if a
+ feedback = ''
+ description = ''
Dir.open(systempath).each do |e|
begin
@@ -228,47 +186,44 @@ class Ambindextrous < FCGILet
LOGGER.debug e.inspect
- entry = {
- :pathurl => Amrita::SanitizedString.new(e.urlencode),
- :path => e,
- :extension => extension,
- :description => (log_errors { File.get_attr(qp, 'description') } rescue ''),
- :images => (log_errors { make_thumburls(File.images(qp), e) } rescue ""),
- :type => if s.directory? then '/' else '' end,
- :time => s.mtime.strftime('%e %b %y'),
- :size => File.contentsize(qp)
- }
+ entry = OpenStruct.new
+ entry.pathurl = e.urlencode
+ entry.path = e
+ entry.extension = extension
+ entry.description = ''
+ entry.images = (log_errors { make_thumburls(File.images(qp), e) } rescue "")
+ entry.type = if s.directory? then '/' else '' end
+ entry.time = s.mtime.strftime('%e %b %y')
+ entry.size = File.contentsize(qp)
if /[.](jpg|jpeg|gif|png|svg)/i =~ e
- entry[:thumbnail] = '/global-site-overlay/ambindextrous/bin/thumbnailer/128x128' + File.join(self.url.path, e.urlencode)
- data[:images] << entry
+ entry.thumbnail = '/global-site-overlay/ambindextrous/bin/thumbnailer/128x128' + File.join(self.url.path, e.urlencode)
+ images << entry
else
- data[:entries] << entry
+ entries << entry
end
rescue Exception => x
LOGGER.debug x + " " + x.backtrace.join(", ")
end
end
if !do_images
- data[:entries] += data[:images]
+ entries += images
end
- data[:images].sort! { |x,y| x[:path] <=> y[:path] }
- data[:entries].sort! { |x,y| x[:path] <=> y[:path] }
- LOGGER.debug { data[:images].inspect }
- template.expand out, data
+ images.sort! { |x,y| x.path <=> y.path }
+ entries.sort! { |x,y| x.path <=> y.path }
+ LOGGER.debug { images.inspect }
+ out.puts(template.result(binding))
end
def make_thumburls(images, e)
- Amrita::SanitizedString.new(
- if images.empty?
- ""
- else
- images.map { |i|
- #f = File.join(File.basename(filename), i)
- # FIXME: proper URL escaping
- "<a href='#{File.join(e, i)}'><img src='#{File.join('/global-site-overlay/ambindextrous/bin/thumbnailer/32x24', self.url.path, e, i)}' alt='#{i}' title='#{i}' /></a>"
- }.join(' ')
- end
- )
+ if images.empty?
+ ""
+ else
+ images.map { |i|
+ #f = File.join(File.basename(filename), i)
+ # FIXME: proper URL escaping
+ "<a href='#{File.join(e, i)}'><img src='#{File.join('/global-site-overlay/ambindextrous/bin/thumbnailer/32x24', self.url.path, e, i)}' alt='#{i}' title='#{i}' /></a>"
+ }.join(' ')
+ end
end
end
View
0 bin/thumbnailer 100644 → 100755
No changes.
@@ -11,7 +11,7 @@ class FreedesktopThumbnailer < Cacher
SIZE_NAMES = SIZES.invert
attr_accessor :size, :sizename
- CacheDirs = [File.join(ENV['HOME'], '.thumbnails'), '/tmp/thumbnails']
+ CacheDirs = ['/var/cache/thumbnailer', File.join(ENV['HOME'], '.thumbnails'), '/tmp/thumbnails']
def initialize(size)
if !/x/.match(size)
size = SIZES[size]
@@ -12,7 +12,7 @@ class WebThumbnailer < Cacher
SIZE_NAMES = SIZES.invert
attr_accessor :x, :y, :sizename
- CacheDirs = [File.join(ENV['HOME'] || '/tmp', '.thumbnails'), '/tmp/thumbnails']
+ CacheDirs = ['/var/cache/thumbnailer', File.join(ENV['HOME'] || '/tmp', '.thumbnails'), '/tmp/thumbnails']
def initialize(size)
if !/x/.match(size)
size = SIZES[size]
View
@@ -10,7 +10,7 @@ def formdecode
self.gsub('+', ' ').urldecode
end
def urlencode
- self.gsub('%', '%25').gsub(' ', '%20').gsub('?', '%3F')
+ self.gsub('%', '%25').gsub(' ', '%20').gsub('?', '%3F').gsub("'", '%27').gsub('"', '%22')
end
end
@@ -24,7 +24,7 @@ def docroot
path = env['REQUEST_URI'].split('?')[0].urldecode
end
if path =~ %r{/~([^/]+)}
- docroot = File.join(Etc.getpwnam($1).dir, (if selfurl.host =~ /evil/: 'evil' else 'web' end))
+ docroot = File.join(Etc.getpwnam($1).dir, (if selfurl.host =~ /evil/ then 'evil' else 'web' end))
end
docroot
end

0 comments on commit 9feeca4

Please sign in to comment.