diff options
author | Jochen Topf <jochen@topf.org> | 2013-01-14 22:13:07 +0100 |
---|---|---|
committer | Jochen Topf <jochen@topf.org> | 2013-01-14 22:13:07 +0100 |
commit | 267f61dc4f6b40f55ec661738cdb44e834df3485 (patch) | |
tree | a0f9807fb5f5feb225f2d45be37c4cb3dd9992b0 /web | |
parent | 9d732da11731a0162839eca98b5de19f76e661a7 (diff) | |
download | taginfo-267f61dc4f6b40f55ec661738cdb44e834df3485.tar taginfo-267f61dc4f6b40f55ec661738cdb44e834df3485.tar.gz |
Remove some functions from ruby code.
Those pretty print and link functions are available in Javascript, too. To
avoid code duplication, I changed the few places where those functions were
used to use the Javascript ones.
Diffstat (limited to 'web')
-rw-r--r-- | web/lib/utils.rb | 80 | ||||
-rw-r--r-- | web/views/key.erb | 3 | ||||
-rw-r--r-- | web/views/relation.erb | 6 | ||||
-rw-r--r-- | web/views/tag.erb | 10 |
4 files changed, 13 insertions, 86 deletions
diff --git a/web/lib/utils.rb b/web/lib/utils.rb index 9c7464f..298ee64 100644 --- a/web/lib/utils.rb +++ b/web/lib/utils.rb @@ -110,86 +110,6 @@ def get_total(type) return @db.stats(key) end -# see also web/public/js/taginfo.js -def pp_key(key) - if key == '' - return '<span class="badchar empty">empty string</span>' - end - - pp_chars = '!"#$%&()*+,/;<=>?@[\\]^`{|}~' + "'"; - - result = '' - key.each_char do |c| - if (!pp_chars.index(c).nil?) - result += '<span class="badchar">' + c + '</span>' - elsif (c == ' ') - result += '<span class="badchar">␣</span>' - elsif (c.match(/\s/)) - result += '<span class="whitespace"> </span>' - else - result += c; - end - end - - return result; -end - -# see also web/public/js/taginfo.js -def pp_value(value) - if value == '' - return '<span class="badchar empty">empty string</span>' - end - return escape_html(value).gsub(/ /, '␣').gsub(/\s/, '<span class="whitespace"> </span>') -end - -def pp_rtype(rtype) - if rtype == '' - return '<span class="badchar empty">empty string</span>' - end - - pp_chars = '!"#$%&()*+,/;<=>?@[\\]^`{|}~' + "'"; - - result = '' - rtype.each_char do |c| - if (!pp_chars.index(c).nil?) - result += '<span class="badchar">' + c + '</span>' - elsif (c == ' ') - result += '<span class="badchar">␣</span>' - elsif (c.match(/\s/)) - result += '<span class="whitespace"> </span>' - else - result += c; - end - end - - return result; -end - -def link_to_key(key, tab='') - k = escape(key) - - if key.match(/[=\/]/) - return '<a href="/keys/?key=' + k + tab + '">' + pp_key(key) + '</a>' - else - return '<a href="/keys/' + k + tab + '">' + pp_key(key) + '</a>' - end -end - -def link_to_value(key, value) - k = escape(key) - v = escape(value) - - if key.match(/[=\/]/) || value.match(/[=\/]/) - return '<a href="/tags/?key=' + k + '&value=' + v + '">' + pp_value(value) + '</a>' - else - return '<a href="/tags/' + k + '=' + v + '">' + pp_value(value) + '</a>' - end -end - -def link_to_tag(key, value) - return link_to_key(key) + '=' + link_to_value(key, value) -end - # Like the 'get' method but will add a redirect for the same path with trailing / added def get!(path, &block) get path, &block diff --git a/web/views/key.erb b/web/views/key.erb index c51af26..e636b26 100644 --- a/web/views/key.erb +++ b/web/views/key.erb @@ -16,7 +16,7 @@ <span class="button disabled" title="Button disabled, because there are too many objects with this key">JOSM</span> <% end %> </div> - <h1><%= pp_key(@key) %></h1> + <h1></h1> <p><%= @desc %></p> </div> <div id="tabs"> @@ -105,6 +105,7 @@ JS.raw(<<"JAVASCRIPT") function page_init2() { var key = #{ @key.to_json }; + jQuery('h1').html(pp_key(key)); init_tabs([key, #{ @filter_type.to_json }, #{ r18n.locale.code.to_json }]); create_chart({ key: key, diff --git a/web/views/relation.erb b/web/views/relation.erb index 19dcc9f..0c6b066 100644 --- a/web/views/relation.erb +++ b/web/views/relation.erb @@ -1,5 +1,5 @@ <div class="pre"> - <h1><%= t.pages.relation.name %> '<%= pp_rtype(@rtype) %>'</h1> + <h1></h1> <p><%= @desc %></p> </div> <div id="tabs"> @@ -23,7 +23,9 @@ <% javascript do JS.raw(<<"JAVASCRIPT") function page_init2() { - init_tabs([#{ @rtype.to_json }]); + var rtype = #{ @rtype.to_json }; + jQuery('h1').html("#{ t.pages.relation.name } '" + pp_rtype(rtype) + "'"); + init_tabs([rtype]); } JAVASCRIPT end diff --git a/web/views/tag.erb b/web/views/tag.erb index 243954d..d9ef5a2 100644 --- a/web/views/tag.erb +++ b/web/views/tag.erb @@ -16,7 +16,7 @@ <span class="button disabled" title="Button disabled, because there are too many objects with this key">JOSM</span> <% end %> </div> - <h1><%= link_to_key(@key) %>=<%= pp_value(@value) %></h1> + <h1></h1> <p><%= @desc %></p> </div> <div id="tabs"> @@ -50,7 +50,7 @@ <table id="grid-wiki"> </table> <% else %> - <p class="empty"><%= t.pages.tag.wiki_pages.none_found %> <%= @wiki_count_key > 0 ? t.pages.tag.wiki_pages.suggest_key_wiki_page(link_to_key(@key, '#wiki')) : '' %></p> + <p class="empty"><%= t.pages.tag.wiki_pages.none_found %> <%= @wiki_count_key > 0 ? t.pages.tag.wiki_pages.suggest_key_wiki_page('<span id="keylink"></span>') : '' %></p> <p><a class="extlink" target="_blank" rel="nofollow" href="http://wiki.openstreetmap.org/w/index.php?action=edit&title=Tag:<%= escape(@tag) %>"><%= t.pages.tag.wiki_pages.create %></a></p> <% end %> </div> @@ -74,7 +74,11 @@ <% javascript do JS.raw(<<"JAVASCRIPT") function page_init2() { - init_tabs([#{ @key.to_json }, #{ @value.to_json }, #{ @filter_type.to_json }]); + var key = #{ @key.to_json }, + value = #{ @value.to_json }; + jQuery('h1').html(link_to_key(key) + '=' + pp_value(value)); + jQuery('span#keylink').html(link_to_key(key)); + init_tabs([key, value, #{ @filter_type.to_json }]); } JAVASCRIPT end |