Permalink
Browse files

Extracted from innate

  • Loading branch information...
manveru committed Oct 12, 2008
0 parents commit ef045258c2e43702357c1a10d99e16fb0996544d
Showing with 4,624 additions and 0 deletions.
  1. +58 −0 bin/graph
  2. +114 −0 env.rb
  3. +23 −0 layout/default.haml
  4. +150 −0 model/page.rb
  5. +7 −0 node/css.rb
  6. +9 −0 node/dot.rb
  7. +2 −0 node/init.rb
  8. +165 −0 node/page.rb
  9. +1 −0 pages
  10. +114 −0 public/css/active4d.css
  11. +108 −0 public/css/all_hallows_eve.css
  12. +147 −0 public/css/amy.css
  13. +88 −0 public/css/blackboard.css
  14. +605 −0 public/css/brilliance_black.css
  15. +599 −0 public/css/brilliance_dull.css
  16. +149 −0 public/css/cobalt.css
  17. +121 −0 public/css/dawn.css
  18. +121 −0 public/css/eiffel.css
  19. +109 −0 public/css/espresso_libre.css
  20. +62 −0 public/css/idle.css
  21. +80 −0 public/css/iplastic.css
  22. +73 −0 public/css/lazy.css
  23. +123 −0 public/css/mac_classic.css
  24. +104 −0 public/css/magicwb_amiga.css
  25. +188 −0 public/css/pastels_on_dark.css
  26. +85 −0 public/css/slush_poppies.css
  27. +51 −0 public/css/spacecadet.css
  28. +180 −0 public/css/sunburst.css
  29. +137 −0 public/css/twilight.css
  30. +91 −0 public/css/zenburnesque.css
  31. BIN public/favicon.ico
  32. BIN public/favicon.ico.png
  33. BIN public/swf/ramaze-action-parameters.swf
  34. BIN public/swf/ramaze-forms.swf
  35. BIN public/swf/ramaze-hello-world.swf
  36. BIN public/swf/ramaze-layouts.swf
  37. BIN public/swf/ramaze-templates.swf
  38. +39 −0 start.rb
  39. +94 −0 vendor/feed_convert.rb
  40. +24 −0 vendor/git_extension.rb
  41. +161 −0 vendor/rack/localize.rb
  42. +104 −0 view/css/coderay.css
  43. +106 −0 view/css/screen.css.sass
  44. +123 −0 view/css/uv.css
  45. +11 −0 view/delete.haml
  46. +17 −0 view/diff.haml
  47. +19 −0 view/edit.haml
  48. +31 −0 view/history.haml
  49. +13 −0 view/index.haml
  50. +5 −0 view/list.haml
  51. +13 −0 view/show.haml
@@ -0,0 +1,58 @@
+#!/usr/bin/env ruby
+
+require 'owlscribble'
+require 'tempfile'
+require 'pp'
+require 'rack'
+
+$pages = {}
+
+OWLScribble.each_wiki_link do |tag, page_name, link_text|
+ $pages[$page] << page_name
+
+ tag.name = 'a'
+ tag.href = "/#{Rack::Utils.escape(page_name)}"
+ tag.text = link_text.dewikiword
+ #c = Page[page_name].exists? ? 'existing-wiki-link' : 'missing-wiki-link'
+ tag.class = 'foo'
+end
+
+OWLScribble.each_wiki_command do |tag, command, params|
+ case command
+ when 'include'
+ tag.name = 'div'
+ tag.class = 'included'
+ tag.text = Page.get(*params).render
+ else
+ tag.name = 'span'
+ tag.class = 'unhandled_command'
+ tag.text = "###{command}( #{params.join ', '} )##"
+ end
+end
+
+existing = []
+
+Dir['pages/*.owl'].each do |file|
+ $page = File.basename(file, '.owl')
+ $pages[$page] ||= []
+ existing << $page
+ owl = OWLScribble.new(File.read(file))
+end
+
+Tempfile.open('graph.dot') do |dot|
+ dot.puts 'Digraph Wiki {'
+
+ $pages.each do |page, links|
+ links.each do |link|
+ color = existing.include?(link) ? '#0000ff' : '#ff0000'
+ dot.puts %( #{page} -> #{link} [color="#{color}"];)
+ end
+ end
+
+ dot.puts '}'
+ dot.close
+
+ system('dot', '-Tpng', '-O', dot.path)
+ system('feh', png = "#{dot.path}.png")
+ puts png
+end
114 env.rb
@@ -0,0 +1,114 @@
+Options.for(:wiki){|wiki|
+ wiki.title = 'Ramaze Wiki'
+ wiki.root = File.dirname(__FILE__)
+ wiki.repo = File.expand_path(ENV['WIKI_HOME'] || File.join(wiki.root, 'pages'))
+ wiki.default_language = 'en'
+}
+
+module Org
+ class Token
+ include ToHtml
+ include ToToc
+
+ def html_a
+ link, desc = *values
+
+ if link =~ /:/
+ leader, rest = link.split(/:/, 2)
+
+ case leader
+ when /^(https?|ftps?)$/
+ link_external(link, desc || link)
+ when /^swf$/
+ link_swf(rest, desc)
+ when /^irc$/
+ link_irc(rest, desc)
+ when /^wp$/
+ link_wikipedia(rest, desc)
+ when /^feed|rss|atom$/
+ link_feed(rest, desc)
+ else
+ link_external(link, desc || link)
+ end
+ else
+ link_internal(link, desc || link)
+ end
+ end
+
+ LINKS = {} unless defined?(LINKS)
+
+ def link_internal(link, desc)
+ this = Innate::Current::action.params.join('/')
+ exists = Page.new(link.split('#').first, :speedup).exists?
+ style = "#{exists ? 'existing' : 'missing'}-wiki-link"
+ tag(:a, desc, :href => PageNode.r(link), :class => style)
+ end
+
+ def link_external(link, desc)
+ tag(:a, desc, :href => link, :class => 'wiki-link-external')
+ end
+
+ def link_irc(link, desc)
+ tag(:a, desc, :href => "irc://#{link}", :class => 'wiki-link-external')
+ end
+
+ def link_feed(link, desc)
+ feed = FeedConvert.parse(open(link))
+
+ b = Builder::XmlMarkup.new
+
+ b.div(:class => 'feed') do
+ b.h2{ b.a(feed.title, :href => feed.link) } if desc
+
+ b.ul do
+ feed.items.map do |item|
+ b.li do
+ b.a(item.title, :href => item.link)
+ end
+ end
+ end
+ end
+
+ b.target!
+ rescue SocketError # so i can work on it local
+ link = '/home/manveru/feeds/rss_v2_0_msgs.xml'
+ retry
+ end
+
+ # TODO: format for search or name of article.
+ # "I'm feeling lucky" google search for wp might be best?
+ def link_wikipedia(term, desc)
+ # query = Rack::Utils.escape("site:wikipedia.org #{term}")
+ # href = "http://google.com/?q=#{query}"
+ term = Rack::Utils.escape(term)
+ tag(:a, desc, :href => "http://en.wikipedia.org/w/#{term}", :class => 'wiki-link-external')
+ end
+
+ # what a fantastically cheap hack :)
+ # use in your wiki like:
+ # [[swf:some-vid][width: 600; height: 700; play: true]]
+ SWF_DEFAULT = '; loop: false; quality: low; play: false'
+
+ def link_swf(file, args)
+ args << SWF_DEFAULT << "; movie: /swf/#{file}.swf"
+ template = SWF_TEMPLATE.dup
+ args.split(/\s*;\s*/).each do |subarg|
+ key, value = subarg.split(/\s*:\s*/)
+ template.gsub!("{#{key}}", value.dump)
+ end
+
+ return template
+ end
+
+ SWF_TEMPLATE = <<'SWF_TEMPLATE'
+<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width={width} height={height} codebase="http://active.macromedia.com/flash5/cabs/swflash.cab#version=5,0,0,0">
+ <param name=movie value={movie}>
+ <param name=play value={play}>
+ <param name=loop value={loop}>
+ <param name=quality value={quality}>
+ <embed src="{movie}" width={width} height={height} quality={quality} loop={loop} type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">
+ </embed>
+</object>
+SWF_TEMPLATE
+ end
+end
@@ -0,0 +1,23 @@
+!!! XML
+!!!
+
+%html
+ %head
+ %title Innate Wiki
+ %link{:rel => 'stylesheet', :href => '/css/screen.css', :type => 'text/css'}
+ %link{:rel => 'stylesheet', :href => '/css/coderay.css', :type => 'text/css'}
+ - if uv_style = session[:uv_style]
+ %link{:rel => 'stylesheet', :href => "/css/#{uv_style}.css", :type => 'text/css'}
+ %body
+ .head
+ .title
+ %a{:href => '/Home', :alt => 'Home'}
+ %h1 Innate Wiki
+ %h2 A minimal git based wiki
+ .menu
+ %a{:href => '/list'} List Pages
+ %a{:href => r(:random)} Random Page
+ .locale
+ %a{:href => r(:language, 'en')} English
+ %a{:href => r(:language, 'ja')} 日本語
+ .content= content
@@ -0,0 +1,150 @@
+require 'logger'
+require 'vendor/git_extension'
+
+class Page
+ C = Options.for(:wiki)
+ GBLOB_CACHE = {}
+ LOG_CACHE = {}
+ EXT = '.org'
+
+ begin
+ G = Git.open(C.repo, :log => Innate::Log)
+ rescue ArgumentError
+ FileUtils.mkdir_p(C.repo)
+ Dir.chdir(C.repo){ Git.init('.') }
+ retry
+ end
+
+ def self.[](name)
+ new(name)
+ end
+
+ def self.language
+ Innate::Current.session[:language] || C.default_language
+ end
+
+ def self.list(language)
+ Dir["#{C.repo}/#{language}/**/*#{EXT}"].map{|path|
+ path.gsub(C.repo, '').gsub(/#{language}\//, '').gsub(/#{EXT}$/, '')[1..-1]
+ }
+ end
+
+ def self.list_render
+ out = ["* List"] + list.map{|path| " * [[#{path}]]" }
+ render(out * "\n")
+ end
+
+ def self.diff(sha, style)
+ require 'uv'
+ diff = G.diff(sha).patch
+ Uv.parse(diff, output = 'xhtml', syntax_name = 'diff', line_numbers = false, render_style = style, headers = false)
+ end
+
+ def diff(sha, style)
+ diff = G.gcommit(sha).diff(repo_file).patch
+ Uv.parse(diff, output = 'xhtml', syntax_name = 'diff', line_numbers = false, render_style = style, headers = false)
+ end
+
+ def self.show(sha, file)
+ G.gblob("#{sha}:#{file}").contents
+ end
+
+ def initialize(name, revision = nil)
+ @name = name
+ @org = nil
+ @revision = revision || revisions.first
+ end
+
+ def read(rev = @revision)
+# return File.read(file)
+ return nil unless rev
+ ref = "#{rev}:#{repo_file}"
+ GBLOB_CACHE[ref] ||= G.gblob(ref).contents + "\n"
+ rescue Git::GitExecuteError => ex
+ p :read => ex
+ nil
+ rescue Errno::ENOENT
+ nil
+ end
+
+ def revisions
+ object = "-- #{repo_file}"
+ LOG_CACHE[object] = G.lib.log_commits(:object => object)
+ rescue Git::GitExecuteError => ex
+ p :revisions => ex
+ []
+ end
+
+ # TODO: make sure this is threadsafe
+ def save(content, comment = "Update #@name")
+ FileUtils.mkdir_p(File.dirname(file))
+ File.open(file, 'w+'){|i|
+ i.puts content.gsub(/\r\n|\r/, "\n")
+ }
+ G.add(repo_file)
+ message = G.commit(comment)
+ @revision = message[/Created commit (\w+):/, 1]
+ rescue Git::GitExecuteError => ex
+ puts ex
+ nil
+ ensure
+ GBLOB_CACHE.clear
+ LOG_CACHE.clear
+ end
+
+ # TODO: make sure this is threadsafe
+ def move(to, comment = "Move #@name to #{to}")
+ return unless exists?
+ return if @name == to
+ G.lib.mv(repo_file, repo_file(to))
+ message = G.commit(comment)
+ @revision = message[/Created commit (\w+):/, 1]
+ @name = to
+ rescue Git::GitExecuteError => ex
+ puts "move(%p, %p)" % [to, comment]
+ p ex
+ nil
+ end
+
+ def history
+ G.lib.log_commits_follow(:object => repo_file).map do |rev|
+ G.gcommit(rev)
+ end
+ end
+
+ def render(string = content)
+ self.class.render(string)
+ end
+
+ def to_html
+ org.to_html
+ end
+
+ def to_toc
+ org.to_toc
+ end
+
+ def org
+ @org ||= Org::OrgMode.apply(content)
+ end
+
+ def file
+ File.join(C.repo, repo_file)
+ end
+
+ def repo_file(name = @name)
+ File.join *"#{language}/#{name}#{EXT}".split('/')
+ end
+
+ def language
+ self.class.language
+ end
+
+ def content
+ read || ''
+ end
+
+ def exists?
+ File.file?(file)
+ end
+end
@@ -0,0 +1,7 @@
+class CSSNode
+ include Innate::Node
+ map '/css'
+
+ provide :css => :none # serve .css plain
+ provide :sass => :sass # serve .css.sass through Sass
+end
@@ -0,0 +1,9 @@
+class Dot
+ include Innate::Node
+ map '/dot'
+
+ def generate
+ png = `bin/graph`
+ FileUtils.cp(png 'public/graph.png')
+ end
+end
@@ -0,0 +1,2 @@
+require 'node/css'
+require 'node/page'
Oops, something went wrong.

0 comments on commit ef04525

Please sign in to comment.