forked from rorx/redmine_wiki_sql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.rb
executable file
·53 lines (45 loc) · 1.42 KB
/
init.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
require 'redmine'
require 'open-uri'
require 'issue'
Redmine::Plugin.register :redmine_wiki_sql do
name 'Redmine Wiki SQL'
author 'Rodrigo Ramalho'
author_url 'http://www.rodrigoramalho.com/'
description 'Allows you to run SQL queries and have them shown on your wiki in table format'
version '0.0.1'
Redmine::WikiFormatting::Macros.register do
desc "Run SQL query"
macro :sql do |obj, args|
_sentence = args.join(",")
_sentence = _sentence.gsub("\\(", "(")
_sentence = _sentence.gsub("\\)", ")")
result = ActiveRecord::Base.connection.select_all _sentence
unless result.nil?
_line = result[0]
unless _line.nil?
_thead = '<tr>'
_line.each do |key,value|
_thead << '<th>' + key.to_s + '</th>'
end
_thead << '</tr>'
_tbody = ''
result.each do |record|
unless record.nil?
_tbody << '<tr>'
record.each do |key,value|
_tbody << '<td>' + value.to_s + '</td>'
end
_tbody << '</tr>'
end
end
_table = '<table>' << _thead << _tbody << '</table>'
return _table
else
return ''
end
else
return ''
end
end
end
end