From pema at dri.cefetmg.br Fri Mar 5 18:15:31 2010 From: pema at dri.cefetmg.br (Paulo Almeida) Date: Fri, 5 Mar 2010 15:15:31 -0800 (PST) Subject: [webgen-users] Global variables Message-ID: Hello, I am trying to use global variables, as pointed out at webgen FAQ page, but no success. I am trying to put the following lines at config.yaml file: Core/Configuration: customVars: {myVar: This is really nice!} I always get the error message: > An error has occurred: > Configuration invalid: No such configuration option: customVars What am I missing here? Is there another way to define global values (numbers, strings etc.) and use them in lots of pages? Thx for your attention. From t_leitner at gmx.at Sat Mar 6 03:21:49 2010 From: t_leitner at gmx.at (Thomas Leitner) Date: Sat, 6 Mar 2010 09:21:49 +0100 Subject: [webgen-users] Global variables In-Reply-To: References: Message-ID: <20100306092149.663e649c@noeato.mat.univie.ac.at> On Fri, 5 Mar 2010 15:15:31 -0800 (PST), Paulo Almeida wrote: > Hello, > > I am trying to use global variables, as pointed out at webgen FAQ > page, but no success. I am trying to put the following lines at > config.yaml file: > > Core/Configuration: > customVars: > {myVar: This is really nice!} > > I always get the error message: > > > An error has occurred: > > Configuration invalid: No such configuration option: customVars > > What am I missing here? Which version of webgen are you using? From the example above, it seems that you are using webgen 0.4.x (and therefore the FAQ from http://webgen.rubyforge.org/documentation/0.4.x/documentation/howto.html). Note that there is an error in your example above: You need to indent customVars with two spaces: Core/Configuration: customVars: myVar: This is really nice The above should work. Best regards, Thomas From pema at dri.cefetmg.br Sat Mar 6 09:41:04 2010 From: pema at dri.cefetmg.br (Paulo Almeida) Date: Sat, 6 Mar 2010 06:41:04 -0800 (PST) Subject: [webgen-users] Global variables In-Reply-To: <20100306092149.663e649c@noeato.mat.univie.ac.at> References: <20100306092149.663e649c@noeato.mat.univie.ac.at> Message-ID: <5e5e2ad6-b72a-44c0-9165-2b470e94ed15@g19g2000yqe.googlegroups.com> Hi Thomas, Thx for your response. I think I mixed up something here. Actually, I am using version 0.5.11 and used FAQ from version 0.4, sorry for my mistake. Anyway, is there a way to create global variables or a similar resource in version 0.5? My problem is: I have some values (integers and strings) which may eventually change with time, such that each time I recompile my website (using 'webgen' command) they could be grabbed from global variables (or maybe from a data file) to be translated to html format. So every time they change, I can update just one place (config.yaml ou any other data file) and they will be changed in every page that uses them. Regards, Paulo On 6 mar, 05:21, Thomas Leitner wrote: > On Fri, 5 Mar 2010 15:15:31 -0800 (PST), Paulo Almeida wrote: > > Hello, > > > I am trying to use global variables, as pointed out at webgen FAQ > > page, but no success. I am trying ?to put the following lines at > > config.yaml file: > > > Core/Configuration: > > customVars: > > ? {myVar: This is really nice!} > > > I always get the error message: > > > > An error has occurred: > > > Configuration invalid: No such configuration option: customVars > > > What am I missing here? > > Which version of webgen are you using? From the example above, it seems > that you are using webgen 0.4.x (and therefore the FAQ fromhttp://webgen.rubyforge.org/documentation/0.4.x/documentation/howto.html). > Note that there is an error in your example above: You need to indent > customVars with two spaces: > > Core/Configuration: > ? customVars: > ? ? myVar: This is really nice > > The above should work. > > Best regards, > ? Thomas > _______________________________________________ > webgen-users mailing list > webgen-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/webgen-users From mmayer at opencsw.org Tue Mar 9 00:10:53 2010 From: mmayer at opencsw.org (Markus Mayer) Date: Mon, 08 Mar 2010 21:10:53 -0800 Subject: [webgen-users] Conditional sidebar Message-ID: <4B95D85D.5040800@opencsw.org> Hi, I am obviously new to webgen, as my problem is a fairly simple yet one that I can't seem to solve on my own. I am using webgen 0.5.11. I only want those pages that have "has_sidebar: true" is set in their page header to have a side bar. Like so: --- title: Welcome in_menu: true routed_title: Home sort_info: 0 has_sidebar: true --- [Rest of the page goes here] I did find this post: http://rubyforge.org/pipermail/webgen-users/2008-October/000346.html Accordingly, I tried: <% if node['has_sidebar'] == "true" %> [HTML block that generates side-bar] <% end %> All that earns me, however, is An error has occurred: Error in while rendering with Webgen::ContentProcessor::Erb: undefined local variable or method `node' for # If I use <% if content_node.node_info[:page].blocks.has_key?('has_sidebar') %> instead, I get get an error as well: undefined local variable or method `content_node' for # I am clearly doing something very obvious wrong. Does anybody have any pointers what that might be? Thanks, -Markus From t_leitner at gmx.at Tue Mar 9 01:27:47 2010 From: t_leitner at gmx.at (Thomas Leitner) Date: Tue, 9 Mar 2010 07:27:47 +0100 Subject: [webgen-users] Conditional sidebar In-Reply-To: <4B95D85D.5040800@opencsw.org> References: <4B95D85D.5040800@opencsw.org> Message-ID: <20100309072747.5ce6fc1c@noeato.mat.univie.ac.at> > If I use > <% if content_node.node_info[:page].blocks.has_key?('has_sidebar') %> > instead, I get get an error as well: > > undefined local variable or method `content_node' for > # The direct use of the variables you use has been deprecated in favour of the `context` object. So your code should read: <% if context.content_node['has_sidebar'] %> [HTML block that generates side-bar] <% end %> Also note that the page meta information block is parsed with YAML, meaning that the keys and values are converted, as far as possible, to equivalent Ruby objects. Given your example, the value for the `has_sidebar` key will be converted to the boolean value `true`. Therefore the above if-condition is sufficient. -- Thomas From t_leitner at gmx.at Tue Mar 9 01:42:12 2010 From: t_leitner at gmx.at (Thomas Leitner) Date: Tue, 9 Mar 2010 07:42:12 +0100 Subject: [webgen-users] Global variables In-Reply-To: <5e5e2ad6-b72a-44c0-9165-2b470e94ed15@g19g2000yqe.googlegroups.com> References: <20100306092149.663e649c@noeato.mat.univie.ac.at> <5e5e2ad6-b72a-44c0-9165-2b470e94ed15@g19g2000yqe.googlegroups.com> Message-ID: <20100309074212.3aee5f35@noeato.mat.univie.ac.at> > Thx for your response. I think I mixed up something here. Actually, > I am using version 0.5.11 and used FAQ from version 0.4, sorry for my > mistake. Anyway, is there a way to create global variables or a > similar resource in version 0.5? > > My problem is: I have some values (integers and strings) which may > eventually change with time, such that each time I recompile my > website (using 'webgen' command) they could be grabbed from global > variables (or maybe from a data file) to be translated to html format. > So every time they change, I can update just one place (config.yaml ou > any other data file) and they will be changed in every page that uses > them. There is no support for such global variables in 0.5.x as there was in 0.4.x. However, you have two possibilities: 1. Define the variables in ext/init.rb by storing them in a new configuration option: Webgen.website_access.config.globals({'mykey' => 'value', 'otherkey' => 5}) Then you can access the values using the following ERB fragment in a page or template file: <%= context.website.config['globals']['mykey'] %> 2. Create a meta information file for storing each global variable on each page file that uses it: --- name:alcn **/*.html: mykey: value otherkey: 5 Then you can access the "global variables" in each such page file by using the meta tag: {mykey:} is something as well as {otherkey:} The second variant has the advantage that the page files are automatically regenerated when the values change. And the usage is similar to the one in 0.4.x. So I would try the second variant first! -- Thomas From pema at dri.cefetmg.br Tue Mar 9 17:51:41 2010 From: pema at dri.cefetmg.br (Paulo Almeida) Date: Tue, 9 Mar 2010 14:51:41 -0800 (PST) Subject: [webgen-users] Global variables In-Reply-To: <20100309074212.3aee5f35@noeato.mat.univie.ac.at> References: <20100306092149.663e649c@noeato.mat.univie.ac.at> <5e5e2ad6-b72a-44c0-9165-2b470e94ed15@g19g2000yqe.googlegroups.com> <20100309074212.3aee5f35@noeato.mat.univie.ac.at> Message-ID: <3551e398-2a8e-44e6-a292-99880051d9f5@a18g2000yqc.googlegroups.com> Thank you again, Thomas! The first suggestion you gave me is working but, as a matter of fact, I observed that everytime I changed the values inside init.rb, I had to manually "touch" the .page files in order to force their recompilation by webgen, as you mentioned. Just for the records, I had to replace the expression Webgen.website_access.config.globals({...}) by Webgen::WebsiteAccess.website.config.globals({...}) to make it work. I put the second and preferred suggestion to work with no issues. Everytime that I change values inside "metainfo" file, webgen automagically recompiles all HTML files and updates those variables inside the rendered page, as wished. Best regards and congrats for your good work. Paulo On 9 mar, 03:42, Thomas Leitner wrote: > > Thx for your response. I think I mixed up something here. Actually, > > I am using version 0.5.11 and used FAQ from version 0.4, sorry for my > > mistake. Anyway, is there a way to create global variables or a > > similar resource in version 0.5? > > > ? My problem is: I have some values (integers and strings) ?which may > > eventually change with time, such that each time I recompile my > > website (using 'webgen' command) they could be grabbed from global > > variables (or maybe from a data file) to be translated to html format. > > So every time they change, I can update just one place (config.yaml ou > > any other data file) and they will be changed in every page that uses > > them. > > There is no support for such global variables in 0.5.x as there was in > 0.4.x. However, you have two possibilities: > > 1. Define the variables in ext/init.rb by storing them in a new > ? ?configuration option: > > ? ?Webgen.website_access.config.globals({'mykey' => 'value', 'otherkey' => 5}) > > ? ?Then you can access the values using the following ERB fragment in a > ? ?page or template file: > > ? ?<%= context.website.config['globals']['mykey'] %> > > 2. Create a meta information file for storing each global variable on > ? ?each page file that uses it: > > ? ?--- name:alcn > ? ?**/*.html: > ? ? ?mykey: value > ? ? ?otherkey: 5 > > ? ?Then you can access the "global variables" in each such page file by > ? ?using the meta tag: > > ? ?{mykey:} is something as well as {otherkey:} > > The second variant has the advantage that the page files are > automatically regenerated when the values change. And the usage is > similar to the one in 0.4.x. So I would try the second variant first! > > -- Thomas > _______________________________________________ > webgen-users mailing list > webgen-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/webgen-users