Initial import
[redmine_snipt:redmine_snipt.git] / init.rb
1 #
2 # vendor/plugins/redmine_snipt/init.rb
3 #
4 require 'redmine'
5 require 'net/http'
6
7 Redmine::Plugin.register :redmine_snipt do
8   name 'Redmine Snipt embed plugin'
9   author 'Emergya Consultoría'
10   description 'Plugin that let the user embed into a wiki page a snippet' +
11               'from Snipt.net'
12   version '0.1.0'
13
14   Redmine::WikiFormatting::Macros.register do
15     desc "Embed snippet from Snipt.net. Use:\n\n  !{{snipt(id)}}\n\n" +
16          "Example: \n\n  !{{snipt(21884)}}\n\n"
17     macro :snipt do |obj, args|
18       return if args.empty?
19       result = Net::HTTP.get("snipt.net", "/api/snipts/#{args[0]}.json")
20       snipt = ActiveSupport::JSON.decode result
21       snipt_url = "http://snipt.net/#{snipt['user']}/#{snipt['slug']}"
22       out = ''
23       out << content_tag('span', link_to(h(snipt['description']), snipt_url), :class => 'url')
24       out << content_tag('code', snipt['formatted_code'])
25       content_tag('dl', out)
26     end
27
28   end
29 end