ChiliProject is not maintained anymore. Please be advised that there will be no more updates.
We do not recommend that you setup new ChiliProject instances and we urge all existing users to migrate their data to a maintained system, e.g. Redmine. We will provide a migration script later. In the meantime, you can use the instructions by Christian Daehn.
Liquid legacy layer does not handle macros which generate HTML (Bug #816)
Description
The Liquid legacy layer does not register the macros as Liquid tags using the option html => true which would be required for macros which output HTML instead of Textile formatted text.
History
Updated by Holger Just at 2012-01-05 09:30 am
Why would you think that?
The macro compatibility layer is in source:/lib/redmine/wiki_formatting/macros.rb. There it registers the macro wrapped as a tag with :html => true
. See https://github.com/chiliproject/chiliproject/blob/v3.0.0beta1/lib/redmine/wiki_formatting/macros.rb#L60 for the implementation in the 3.0.0beta1.
- Target version deleted (
3.0.0) - Category changed from Wikis to Text formatting
- Affected version set to 3.0.0
- Status changed from Open to Needs more information
Updated by Andreas Schuh at 2012-01-05 11:12 am
Yes, I just discovered this myself and wanted to update this issue. Sorry for the false alarm.
Thing is that I am having problems with a macro which works just fine with Redmine 1.3.0, but not with ChiliProject 3.0.0beta1 :(
Updated by Holger Just at 2012-01-05 11:36 am
If you provide a bit more information, we might be able to help.
Where can we find the source code of the macro? How do you call it? What output do you expect? What is the actual output?
Updated by Andreas Schuh at 2012-01-05 12:51 pm
That would be great. Yet, the sources are nowhere besides my local working copy b/c the original plugin wasn't written by me and as it is Subversion, I didn't bother cloning it yet. Just started today with it.
In particular, I am working on the Download button plugin written by Andriy to make it fit into ChiliProject 3. Further, I thought a Wiki macro which enables one to place such button anywhere in a Wiki page (including the sidebar using, for example, Andriy's Sidebar content plugin) might be useful. I noticed such functionality on the new SourceForge beta Wiki.
As for the Liquid tags, I need a class derived from ChiliProject::Liquid::Tags::Tag and am in a different scope as where the macro code was executed, I had to, for example, replace all calls to render(), content_tag(),... all those ActiveView helpers.
How can I implement a Liquid tag which makes use of ActiveView ? I.e., as it was possible with the Redmine WikiFormatter macros.
The currently remaining issue is the error: Liquid error: undefined method `url_for' for nil:NilClass. Note that this method is called in the DownloadHelper#download_button method, see here.
Currently, I am doing the following (note that I modified the download_button()
method to not use render()
):
1module DownloadButtonMacroImpl
2 def execute(args)
3 # this version of extract_macro_options() has no problem with URL's
4 # which include = signs as option value
5 fixed_extract_macro_options = lambda { |*keys|
6 options = {}
7 while args.last.to_s.strip =~ %r{^([^=]+)\=(.+)$} && keys.include?($1.downcase.to_sym)
8 options[$1.downcase.to_sym] = $2
9 args.pop
10 end
11 return [args, options]
12 }
13 # parse macro options and do some other stuff
14 # [...]
15 # instantiate new (temporary) download button
16 download = DownloadButton.new(attributes)
17 raise "Failed to instantiate DownloadButton" unless download
18 # render download button - could not use content_tag() here any more
19 out = <<-HTML
20 <div class="download-button" style="#{outer_style}">
21 #{download_button(project, download, :style => inner_style)}
22 </div>
23 HTML
24 out
25 end
26end
27
28begin
29
30 class DownloadButtonTag < ChiliProject::Liquid::Tags::Tag
31 include ActionView::Helpers::TranslationHelper # t(ranslate)
32 include ActionView::Helpers::UrlHelper # url_for
33 include ERB::Util # h(tml_escape)
34 include DownloadHelper # download_button
35 include DownloadButtonMacroImpl # implementation
36
37 def initialize(tag_name, markup, tokens)
38 tag_args = markup.strip.gsub(/^[("']|["')]$/, '')
39 if tag_args.present?
40 @args = tag_args.split(',')
41 else
42 @args = []
43 end
44 super
45 end
46
47 def render(context)
48 @project = Project.find(context['project'].identifier ) if context['project'].present?
49 execute(@args)
50 end
51 end
52
53 ChiliProject::Liquid::Tags::register_tag('download_button', DownloadButtonTag, :html => true)
54
55rescue
56
57 class DownloadButtonMacro
58 include ActionView::Helpers::TranslationHelper # t(ranslate)
59 include ActionView::Helpers::UrlHelper # url_for
60 include ERB::Util # h(tml_escape)
61 include DownloadHelper # download_button
62 include DownloadButtonMacroImpl # implementation
63
64 def initialize(project)
65 @project = project
66 end
67 end
68
69 Redmine::WikiFormatting::Macros.register do
70 desc "Inserts Download button in Wiki pages"
71 macro :download_button do |obj, args|
72 impl = DownloadButtonMacro.new(@project)
73 impl.execute(args)
74 end
75 end
76
77end
BTW All the code for the macro lives at the moment in the init.rb file of the plugin. Where would you usually put such code? I am new to both Ruby and Rails...
On a side note, I had to replace the use of l
(I guessed an alias for localize
, but actually it is used for translation, by t
, the alias for translate
. Can you explain to me what the l
alias as in l(:locale_download)
stands for?!? See http://subversion.andriylesyuk.com/redmine-download/app/helpers/download_helper.rb
Updated by Andreas Schuh at 2012-01-05 07:09 pm
Eventually, I figured it all out.
For everyone who may end up reading the above long comment in the future, the solution was basically to put all the ActiveView related rendering code into a .rhtml/.html.erb file and then to render this partial using the :view object of the context, i.e.,
1def render(context)
2 # [...]
3 context.registers[:view].render :partial "download/tag", :locals => { [...] }
4end
In my particular case, the "download/tag"
partial view itself calls the DownloadHelper#download_button()
method, which in turn renders the partial "download/button"
, the partial which is shared among the sidebar button as known from the version 0.4.5 of the Download button plugin and the just implemented ChiliProject Liquid tag or Redmine Wiki formatting macro. I will push this enhancement of the plugin upstream.
- Status changed from Needs more information to Closed
Updated by Andreas Schuh at 2012-01-05 07:17 pm
Just a correction, the current version of the Download button plugin is 0.0.2, not 0.4.5... :S