Hi, for my isbn plugin, I''m wishing to incldue generated isbn pages in caller pages (the ones with <isbn value=""> tags). But I want my isbn page to be processed before for its tags to be transformed (like the relocatable or other ones). Besides, i do not want its header to be included. Is there an easy solution for that, or should I do the work myself ? -- Nicolas Delsaux N''imprimez ce mail que si vous ne savez pas le lire sur l''?cran : les ?lectrons se recyclent bien, le papier, beaucoup moins bien.
Am Sun, 16 Mar 2008 09:59:09 +0100 schrieb "Nicolas Delsaux" <nicolas.delsaux at gmail.com>:> Hi, > for my isbn plugin, I''m wishing to incldue generated isbn pages in > caller pages (the ones with <isbn value=""> tags). > But I want my isbn page to be processed before for its tags to be > transformed (like the relocatable or other ones). Besides, i do not > want its header to be included. > Is there an easy solution for that, or should I do the work myself ?You can manually include a rendered page in another page by using ERB code. However, there is currently no tag for this. Including a rendered page can be done like this: <%= @plugin_manager[''FileHandlers::PageHandler''].render_node(my_node, ''content'', false) %> Which renders the block ''content'' of node ''my_node'' and don''t uses templates. -- Thomas
On 3/17/08, Thomas Leitner <t_leitner at gmx.at> wrote:> > You can manually include a rendered page in another page by using ERB > code. However, there is currently no tag for this. Including a rendered > page can be done like this: > > <%= @plugin_manager[''FileHandlers::PageHandler''].render_node(my_node, > ''content'', false) %> > > Which renders the block ''content'' of node ''my_node'' and don''t uses > templates. >Ok, but how do i define ''my_node'' ? I fear it must be a webgen node, and that I cannot use ab absolute file path instead ? Besides, I was thinking about using the generated page content by including it during my ContentConverter "call" method, but it does not seems to wrok, unfortunatly. -- Nicolas Delsaux N''imprimez ce mail que si vous ne savez pas le lire sur l''?cran : les ?lectrons se recyclent bien, le papier, beaucoup moins bien.
Am Mon, 17 Mar 2008 13:30:54 +0100 schrieb "Nicolas Delsaux" <nicolas.delsaux at gmail.com>:> On 3/17/08, Thomas Leitner <t_leitner at gmx.at> wrote: > > > > You can manually include a rendered page in another page by using > > ERB code. However, there is currently no tag for this. Including a > > rendered page can be done like this: > > > > <%> > @plugin_manager[''FileHandlers::PageHandler''].render_node(my_node, > > ''content'', false) %> > > > > Which renders the block ''content'' of node ''my_node'' and don''t uses > > templates. > > > Ok, but how do i define ''my_node'' ? > I fear it must be a webgen node, and that I cannot use ab absolute > file path instead ? > Besides, I was thinking about using the generated page content by > including it during my ContentConverter "call" method, but it does not > seems to wrok, unfortunatly. >Yes, ''my_node'' needs to be a webgen node pointing to the page file which you want to have rendered. The node can be found like this: node.resolve_node(''/path/to/pagefile.page'') or using a relative path like node.resolve_node(''../mypagefile.page'') where ''node'' is the node of the page that gets current rendered and this variable is accessible while the content of page is rendered with ERB. As these are plain Ruby commands, they also work in a plugin. So it is possible to include them in your ContentConverter. Can you specify more exactly how you want to page content to be included in the ''call'' method? -- Thomas
On 3/17/08, Thomas Leitner <t_leitner at gmx.at> wrote:> > > Yes, ''my_node'' needs to be a webgen node pointing to the page file > which you want to have rendered. The node can be found like this: > > node.resolve_node(''/path/to/pagefile.page'') > > or using a relative path like > > node.resolve_node(''../mypagefile.page'') > > where ''node'' is the node of the page that gets current rendered and > this variable is accessible while the content of page is rendered with > ERB. > > As these are plain Ruby commands, they also work in a plugin. So it is > possible to include them in your ContentConverter. Can you specify more > exactly how you want to page content to be included in the ''call'' > method? >Remember my isbn crazy plugin ? Well ... in it, i generate, from an isbn number a bunch of pages : one for the product, and one for each person which contributed to (author, translators, ...) I then generate cross-references from them. But, since a simple link in my source page would be kind of useless, I include the product page in the source page, and this is when i want my content to be processed correctly. I''ve already hacked some of your code for that. indeed, for this to work, it''s by far simpler to change the relocatable behaviour to be able to handle absolute destination path. Here is the modification I''ve done ================= a modified relocatable plugin handling absolute destination path ====================== class RelocatableTag < DefaultTag infos( :name => ''Tag/Relocatable'', :author => Webgen::AUTHOR, :summary => ''Adds a relative path to the specified name if necessary'' ) param ''path'', nil, ''The path which should be relocatable'' param ''resolveFragment'', true, ''Specifies if the fragment part (#something) in the path should also be resolved'' set_mandatory ''path'', true register_tag ''relocatable'' def relativize(_source, _dest) sourcedirs = _source.split("/") destdirs = _dest.split("/") source_count = sourcedirs.size dest_count = destdirs.size size = [source_count, dest_count].min src = sourcedirs[0..size] same_path = true src.each_index do |i| if same_path if src[i]!=destdirs[i] same_path = false src[i]=nil end else src[i]=nil end end src.compact! common_size = src.size # -1 is to remove filename returned = "../"*((source_count-1)-common_size) returned << destdirs.slice(common_size, (dest_count-common_size))*"/" return returned end def process_tag( tag, chain ) uri_string = param( ''path'' ) result = '''' unless uri_string.nil? # Before all, check if path is an absolute file path path = File.expand_path(uri_string) # hypothesis : when path is the expanded path, input path was an absolute one that may be relativised if path==uri_string if File.exists? path # path of last opened file stored here current_file_path = File.expand_path(chain.last.node_info[:src]) # Now relativising uri_string = relativize(current_file_path, path) end end begin uri = URI.parse( uri_string ) if uri.absolute? result = uri_string else result = resolve_path( uri, chain ) end log(:error) { "Could not resolve path ''#{uri_string}'' in <#{chain.first.node_info[:src]}>" } if result.empty? rescue URI::InvalidURIError => e log(:error) { "Error while parsing path for tag relocatable in <#{chain.first.node_info[:src]}>: #{e.message}" } end end result end ####### private ####### def query_fragment( uri ) (uri.query.nil? ? '''' : ''?''+ uri.query ) + (uri.fragment.nil? ? '''' : ''#'' + uri.fragment) end def resolve_path( uri, chain ) dest_node = chain.first.resolve_node( uri.path ) if !dest_node.nil? && (File.basename( uri.path ) =dest_node.node_info[:pagename] || dest_node.is_directory?) dest_node = dest_node.node_for_lang( chain.last[''lang''] ) end if !dest_node.nil? && !uri.fragment.nil? && param( ''resolveFragment'' ) dest_node = dest_node.resolve_node( ''#'' + uri.fragment ) end if dest_node.nil? '''' else chain.last.route_to( dest_node.is_fragment? ? dest_node.parent : dest_node ) + query_fragment( uri ) end end end ======================================== end ================================ I think that, added to the erb magick, it could be enough (I''ll check that this evening). -- Nicolas Delsaux N''imprimez ce mail que si vous ne savez pas le lire sur l''?cran : les ?lectrons se recyclent bien, le papier, beaucoup moins bien.
Am Mon, 17 Mar 2008 15:32:07 +0100 schrieb "Nicolas Delsaux" <nicolas.delsaux at gmail.com>:> Remember my isbn crazy plugin ? > Well ... in it, i generate, from an isbn number a bunch of pages : one > for the product, and one for each person which contributed to (author, > translators, ...) > I then generate cross-references from them. > But, since a simple link in my source page would be kind of useless, I > include the product page in the source page, and this is when i want > my content to be processed correctly. > I''ve already hacked some of your code for that. > indeed, for this to work, it''s by far simpler to change the > relocatable behaviour to be able to handle absolute destination path. > Here is the modification I''ve done > > <SNIP/> > > I think that, added to the erb magick, it could be enough (I''ll check > that this evening).Okay. I think that including the rendered page with ERB like I showed you should do the trick. Regarding absolute destination paths: Tag/Relocatable can resolve absolute destination paths just fine. Is your modification doing something special which the default implementation does not do? Just a note: Tag/Relocatable can only resolve nodes that are handled by webgen! -- Thomas
On 3/19/08, Thomas Leitner <t_leitner at gmx.at> wrote:> > Regarding absolute destination paths: Tag/Relocatable can resolve > absolute destination paths just fine. Is your modification doing > something special which the default implementation does not do? Just a > note: Tag/Relocatable can only resolve nodes that are handled by webgen! >In my case, handled paths may not exist yet (as is the case when i link to pages I am currently creating, and have not registered as nodes. Besides, is there a special thing to register a page that my plugin is currently creating in the src folder as a node to be processed ? -- Nicolas Delsaux N''imprimez ce mail que si vous ne savez pas le lire sur l''?cran : les ?lectrons se recyclent bien, le papier, beaucoup moins bien.
Am Wed, 19 Mar 2008 16:49:39 +0100 schrieb "Nicolas Delsaux" <nicolas.delsaux at gmail.com>:> On 3/19/08, Thomas Leitner <t_leitner at gmx.at> wrote: > > > > Regarding absolute destination paths: Tag/Relocatable can resolve > > absolute destination paths just fine. Is your modification doing > > something special which the default implementation does not do? > > Just a note: Tag/Relocatable can only resolve nodes that are > > handled by webgen! > > > In my case, handled paths may not exist yet (as is the case when i > link to pages I am currently creating, and have not registered as > nodes. > Besides, is there a special thing to register a page that my plugin is > currently creating in the src folder as a node to be processed ?Regarding your question: no, there is no such thing. If you need to have the page files written to the src directory, I think I would create a script that creates the needed page files and then just run webgen. If you have no need for actually creating files on the disk, create the nodes while webgen is processing the source files, ie. by creating a file handler that creates these files. Then, when webgen generates the HTML files, all needed nodes are there. -- Thomas
On 3/17/08, Thomas Leitner <t_leitner at gmx.at> wrote:> > Yes, ''my_node'' needs to be a webgen node pointing to the page file > which you want to have rendered. The node can be found like this: > > node.resolve_node(''/path/to/pagefile.page'') > > or using a relative path like > > node.resolve_node(''../mypagefile.page'') > > where ''node'' is the node of the page that gets current rendered and > this variable is accessible while the content of page is rendered with > ERB. >Well, using this method did not seems to work. Instead, i do the following, which seems to do the job quite well : page_handler = {} page_handler.merge!(self.plugin_manager[''ContentConverter/Default''].registered_handlers()) page_handler[''default'']self.plugin_manager[''ContentConverter/Default''].registered_handlers()[''ndx''] product_webpagedata = WebPageData.new(product.get_page, page_handler) returned << product_webpagedata.blocks[''content''].content The registered_handler trick is here since WebPageData relies upon a default renderer. -- Nicolas Delsaux N''imprimez ce mail que si vous ne savez pas le lire sur l''?cran : les ?lectrons se recyclent bien, le papier, beaucoup moins bien.