summaryrefslogtreecommitdiff
path: root/web/lib
diff options
context:
space:
mode:
authorJochen Topf <jochen@topf.org>2010-11-13 21:31:39 +0100
committerJochen Topf <jochen@topf.org>2010-11-13 21:31:39 +0100
commit9db63dc2526bf0b2a94e7a6f37a0f7dabdb8f12d (patch)
tree0d2ae6de413c39c21d30aaf296a98ee37977ab45 /web/lib
parentc82bbe69572398d44187ca7b57b1ce572f435d65 (diff)
downloadtaginfo-9db63dc2526bf0b2a94e7a6f37a0f7dabdb8f12d.tar
taginfo-9db63dc2526bf0b2a94e7a6f37a0f7dabdb8f12d.tar.gz
Multiple changes
* Improved and cleaned up source import scripts * Improved some reports and report overview * New osmium version that uses a better hash function * Some experimental magic to include Javascipt in an easier way (tested in keys.erb)
Diffstat (limited to 'web/lib')
-rw-r--r--web/lib/javascript.rb88
-rw-r--r--web/lib/reports.rb23
-rw-r--r--web/lib/sources.rb57
3 files changed, 159 insertions, 9 deletions
diff --git a/web/lib/javascript.rb b/web/lib/javascript.rb
new file mode 100644
index 0000000..7f43d44
--- /dev/null
+++ b/web/lib/javascript.rb
@@ -0,0 +1,88 @@
+# web/lib/javascript.rb
+
+def javascript(url=nil, &block)
+ @javascript ||= Array.new
+ @javascript << Javascript.new(url, &block)
+end
+
+def javascript_tags
+ @javascript.map{ |js| js.to_html }
+end
+
+class Javascript
+
+ def initialize(file)
+ if file.nil?
+ c = ''
+ r = yield c
+ @content = c + r
+ else
+ @file = file
+ end
+ end
+
+ def to_html
+ if @file.nil?
+ %Q{ <script type="text/javascript">//<![CDATA[\n#{ @content }//]]></script>\n}
+ else
+ %Q{ <script type="text/javascript" src="/js/#{ @file }.js"></script>\n}
+ end
+ end
+
+end
+
+class JQuery
+
+ # "include" the convenience methods from R18n::Helpers.
+ # Uses extend instead of include, because we want this
+ # to work not with instances of JQuery but they should
+ # show up as JQuery class methods.
+ extend R18n::Helpers
+
+ def self.ready
+ "jQuery(document).ready(function() {\n" +
+ yield +
+ "});\n"
+ end
+
+ def self.flexigrid(id, options)
+ defaults = {
+ :method => 'GET',
+ :dataType => 'json',
+ :pagetext => t.flexigrid.pagetext,
+ :pagestat => t.flexigrid.pagestat,
+ :outof => t.flexigrid.outof,
+ :findtext => t.flexigrid.findtext,
+ :procmsg => t.flexigrid.procmsg,
+ :nomsg => t.flexigrid.nomsg,
+ :errormsg => t.flexigrid.errormsg,
+ :showToggleBtn => false,
+ :usepager => true,
+ :useRp => true,
+ :rp => 15,
+ :rpOptions => [10,15,20,25,50,100],
+ }
+ "jQuery('##{id}').flexigrid(" + defaults.merge(options).to_json + ");\n"
+ end
+
+end
+
+class JS
+
+ #
+ # Careful, deep magic!
+ #
+ # We redefine the to_json method of the String argument to return
+ # the raw string. This way we can do JS.raw("foo").to_json and get "foo".
+ #
+ def self.raw(code)
+ code.instance_eval do
+ def to_json
+ to_s
+ end
+ end
+ code
+ end
+
+end
+
diff --git a/web/lib/reports.rb b/web/lib/reports.rb
index 99d500a..0895359 100644
--- a/web/lib/reports.rb
+++ b/web/lib/reports.rb
@@ -11,15 +11,19 @@ class Report
end
end
- def initialize(title, sources)
+ def initialize(title, *sources)
@@reports << self
@title = title
@sources = Hash.new
- sources.each do |s|
- @sources[s] = 1
+ sources.each do |id|
+ @sources[id] = 1
end
end
+ def uses_source?(id)
+ sources.has_key? id
+ end
+
def name
@title.gsub(/ /, '_').downcase
end
@@ -30,9 +34,10 @@ class Report
end
-Report.new 'Characters in Keys', %w(db)
-Report.new 'Frequently Used Keys Without Wiki Page', %w(db wiki)
-Report.new 'Key Lengths', %w(db)
-Report.new 'Language Comparison Table for Keys in the Wiki', %w(wiki)
-Report.new 'Languages', %w(wiki)
-Report.new 'Wiki Pages About Non-Existing Keys', %w(db wiki)
+Report.new 'Characters in Keys', :db
+Report.new 'Frequently Used Keys Without Wiki Page', :db, :wiki
+Report.new 'Key Lengths', :db
+Report.new 'Language Comparison Table for Keys in the Wiki', :wiki
+Report.new 'Languages', :wiki
+Report.new 'Wiki Pages About Non-Existing Keys', :db, :wiki
+
diff --git a/web/lib/sources.rb b/web/lib/sources.rb
new file mode 100644
index 0000000..918dd4d
--- /dev/null
+++ b/web/lib/sources.rb
@@ -0,0 +1,57 @@
+# web/lib/sources.rb
+class Source
+
+ @@sources = Array.new
+
+ attr_reader :id, :name, :data_until, :update_start, :update_end
+
+ # Enumerate all available sources
+ def self.each
+ @@sources.each do |source|
+ yield source
+ end
+ end
+
+ # The number of available sources
+ def self.size
+ @@sources.size
+ end
+
+ # Create new source
+ # id - Symbol with id for this source
+ # name - Name of this source
+ def initialize(id, name, data_until, update_start, update_end)
+ @id = id.to_sym
+ @name = name
+ @data_until = data_until
+ @update_start = update_start
+ @update_end = update_end
+ @@sources << self
+ end
+
+ # The URL where this source is described
+ def url
+ "/sources/#{ @id }"
+ end
+
+ # The img URL of this source
+ def imgurl(size=16)
+ "/img/sources/#{ @id }.#{ size }.png"
+ end
+
+ # Returns img tag for this source
+ def img(size=16)
+ %Q{<img src="#{ imgurl(size) }" alt="#{ name }" title="#{ name }" width="#{ size }" height="#{ size }"/>}
+ end
+
+ # Returns a link to this source
+ def link_img
+ %Q{<a href="#{ url }">#{ img }</a>}
+ end
+
+ # Returns a link to this source
+ def link_name
+ %Q{<a href="#{ url }">#{ name }</a>}
+ end
+
+end