forked from manveru/rakki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
env.rb
166 lines (136 loc) · 4.41 KB
/
env.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# Encoding: UTF-8
module Rakki
include Ramaze::Optioned
options.dsl do
o "Title of site", :title,
"Ramaze Wiki"
o "Root directory", :root,
File.dirname(__FILE__)
o "Git repository location", :repo,
File.expand_path(ENV['WIKI_HOME'] || File.join(self[:root], 'pages'))
o "Default language", :default_language,
'en'
o "languages", :languages, [
['de', 'Deutsch'],
['en', 'English'],
['fr', 'Français'],
['ja', '日本語' ]
]
end
end
Ramaze.options.merge!(
'cache.names' => [:session, :feed, :git_blob, :git_log],
'response.headers' => {
'Accept-Charset' => 'utf-8',
'Content-Type' => 'text/html; charset=utf-' })
DICTIONARY = Ramaze::Helper::Localize::Dictionary.new
Rakki.options.languages.each do |id, name|
file = __DIR__("locale/locale_#{id}.yaml")
begin
DICTIONARY.load(id, :yaml => file)
rescue Errno::ENOENT
FileUtils.touch(file)
retry
end
end
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
lang = Innate::Current::session[:language] ||= 'en'
link_internal(link, lang, desc || link)
end
end
def link_internal(link, lang, desc)
this = Innate::Current::action.params.join('/')
exists = Rakki::Page[link.split('#').first, lang]
style = "#{exists ? 'existing' : 'missing'}-wiki-link"
tag(:a, desc, :href => Rakki::Pages.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 => "#{link}", :class => 'wiki-link-external')
end
def link_feed(link, desc)
cache = Innate::Cache.feed
if content = cache[link]
content
else
content = build_feed(link, desc)
cache.store(link, content, :ttl => 600)
end
return content
rescue SocketError # so i can work on it local
link = '/home/manveru/feeds/rss_v2_0_msgs.xml'
retry
end
def build_feed(link, desc)
feed = open(link){|io| FeedConvert.parse(io) }
xml = Nokogiri::XML::Builder.new do |b|
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
end
xml.to_xml
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