Stefano Crocco
2010-Oct-27 10:23 UTC
[webgen-users] regenerating a page when another file changes
Hello to everyone, I''m using webgen to build a website where some information (in particular the news) are read from a YAML file I have in the src directory. For example mysite/src/news.YAML: 2010-10-27: title: a news content: description of the news 2010-10-24: title: an older news description: description of the older news In the news.page file I have written some ERB code which reads the data contained in news.yaml and generates the appropriate HTML for it. The only problem is that I don''t know how to tell webgen to rebuild the news.html page from news.page whenever news.yaml changes. I looked at the webgen documentation and tried to search google but found nothing. Currently, I''m deleting webgen.cache everytime that news.yaml changes, but I don''t like this solution very much. Is there another way to do what I want? Thanks in advance Stefano
Thomas Leitner
2010-Oct-28 09:00 UTC
[webgen-users] regenerating a page when another file changes
On 2010-10-27 12:23 +0200 Stefano Crocco wrote:> Hello to everyone, > I''m using webgen to build a website where some information (in > particular the news) are read from a YAML file I have in the src > directory. For example > > mysite/src/news.YAML: > > 2010-10-27: > title: a news > content: description of the news > 2010-10-24: > title: an older news > description: description of the older news > > In the news.page file I have written some ERB code which reads the > data contained in news.yaml and generates the appropriate HTML for > it. The only problem is that I don''t know how to tell webgen to > rebuild the news.html page from news.page whenever news.yaml changes. > I looked at the webgen documentation and tried to search google but > found nothing. Currently, I''m deleting webgen.cache everytime that > news.yaml changes, but I don''t like this solution very much. Is there > another way to do what I want?You can use the meta information `used_nodes` (see http://webgen.rubyforge.org/documentation/reference_metainfo.html#usednodes). However, for this to work the file src/news.YAML would need to be processed by a source handler. This can be done by making the copy handler aware of the file by adding the following to config.yaml: patterns: Copy: add: [**/news.YAML] Then you just need two more things: 1. The news.YAML should not actually be copied to the output directory. Create a file src/metainfo with the following contents: news.YAML: no_output: true 2. The page file src/news.page should depend on changes in news.YAML: --- title: News used_nodes: [news.YAML] --- content here I.e. you need to insert the `used_nodes` meta information key. After that every time you change the news.YAML file, the news.page file gets automatically regenerated. -- Thomas
Stefano Crocco
2010-Oct-28 11:44 UTC
[webgen-users] regenerating a page when another file changes
On Thursday 28 October 2010, Thomas Leitner wrote:> |On 2010-10-27 12:23 +0200 Stefano Crocco wrote: > |> Hello to everyone, > |> I''m using webgen to build a website where some information (in > |> particular the news) are read from a YAML file I have in the src > |> directory. [...] > |> The only problem is that I don''t know how to tell webgen to > |> rebuild the news.html page from news.page whenever news.yaml changes.> |You can use the meta information `used_nodes` (see > |http://webgen.rubyforge.org/documentation/reference_metainfo.html#usednode > |s). > | > |However, for this to work the file src/news.YAML would need to be > |processed by a source handler. This can be done by making the copy > |handler aware of the file by adding the following to config.yaml: > | > | patterns: > | Copy: > | add: [**/news.YAML] > | > |Then you just need two more things: > | > |1. The news.YAML should not actually be copied to the output directory. > | Create a file src/metainfo with the following contents: > | > | news.YAML: > | no_output: true > | > |2. The page file src/news.page should depend on changes in news.YAML: > | > | --- > | title: News > | used_nodes: [news.YAML] > | --- > | content here > | > | I.e. you need to insert the `used_nodes` meta information key. > | > |After that every time you change the news.YAML file, the news.page file > |gets automatically regenerated. > | > |-- ThomasThank you very much for your answer. Your suggestion worked perfectly. Stefano
Damien Pollet
2010-Oct-28 12:05 UTC
[webgen-users] regenerating a page when another file changes
Hi Stefano, is your code visible somewhere? I have a [blogging extension for webgen][1] that has a similar problem and I''d like to compare :) I think I''m setting the used_nodes metadata in the code, but probably incorrectly? [1]: http://github.com/cdlm/website/blob/master/ext/blog.rb On Wed, Oct 27, 2010 at 12:23, Stefano Crocco <stefano.crocco at alice.it> wrote:> Hello to everyone, > I''m using webgen to build a website where some information (in particular the > news) are read from a YAML file I have in the src directory. For example > > mysite/src/news.YAML: > > 2010-10-27: > ?title: a news > ?content: description of the news > 2010-10-24: > ?title: an older news > ?description: description of the older news > > In the news.page file I have written some ERB code which reads the data > contained in news.yaml and generates the appropriate HTML for it. The only > problem is that I don''t know how to tell webgen to rebuild the news.html page > from news.page whenever news.yaml changes. I looked at the webgen > documentation and tried to search google but found nothing. Currently, I''m > deleting webgen.cache everytime that news.yaml changes, but I don''t like this > solution very much. Is there another way to do what I want? > > Thanks in advance > > Stefano > _______________________________________________ > webgen-users mailing list > webgen-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/webgen-users >-- Damien Pollet type less, do more [ | ] http://people.untyped.org/damien.pollet
Stefano Crocco
2010-Oct-28 15:02 UTC
[webgen-users] regenerating a page when another file changes
On Thursday 28 October 2010, Damien Pollet wrote:> |Hi Stefano, is your code visible somewhere? > | > |I have a [blogging extension for webgen][1] that has a similar problem > |and I''d like to compare :) > |I think I''m setting the used_nodes metadata in the code, but probably > |incorrectly? > | > |[1]: http://github.com/cdlm/website/blob/master/ext/blog.rbMy code is much more basic than yours, so I don''t think you''d find anything useful in it. However, here''s what it looks like after following Thomas''s instructions: # config.yaml default_processing_pipeline: Page: erb,tags,textile,blocks,fragments patterns: Copy: add: [**/news.yaml] # src/news.page --- title: News in_menu: true sort_info: 25 used_nodes: [news.yaml] --- name:content pipeline:erb,tags,redcloth h2. News <% RuberNews.news_data.each_with_index do |news, idx| %> <div <%= idx > 0 ? ''class="rule" style="padding-top:10px"'' : ''''%> > h3(#<%=news.id%>). <%=news.title%> p{margin-bottom:10px;font-size:1.2em;color:#FF7E80x}. *<%= news.date %>* <%= news.contents %> </div> <%end %> #src/data.metainfo news.yaml: no_output: true #src/news.yaml - title: first news date: 2010-10-28 contents: some text Stefano
Damien Pollet
2010-Oct-28 18:06 UTC
[webgen-users] regenerating a page when another file changes
On Thu, Oct 28, 2010 at 17:02, Stefano Crocco <stefano.crocco at alice.it> wrote:> My code is much more basic than yours, so I don''t think you''d find anything > useful in it. However, here''s what it looks like after following Thomas''s > instructions:Simplicity is interesting as well, thanks :) So I suppose your RuberNews class is just loading the news.yaml file into some Structs ? -- Damien Pollet type less, do more [ | ] http://people.untyped.org/damien.pollet
Stefano Crocco
2010-Oct-28 18:58 UTC
[webgen-users] regenerating a page when another file changes
On Thursday 28 October 2010, Damien Pollet wrote:> |On Thu, Oct 28, 2010 at 17:02, Stefano Crocco <stefano.crocco at alice.it>wrote:> |> My code is much more basic than yours, so I don''t think you''d find > |> anything useful in it. However, here''s what it looks like after > |> following Thomas''s > | > |> instructions: > |Simplicity is interesting as well, thanks :) > |So I suppose your RuberNews class is just loading the news.yaml file > |into some Structs ?That''s about it. It seems I have forgot to add the the contents of ext/init.rb to the last message, so here it is: #ext/init.rb module RuberNews News = Struct.new :title, :date, :contents class News def id "#{title.gsub(/[^\w_-]/, ''-'')}-#{date}" end def format_date date.strftime ''%d %B, %G'' end end def self.news_data data = begin YAML.load(File.read(''src/news.yaml'')) || [] rescue ArgumentError, SystemCallError [] end data.map! do |d| News.new d[''title''], d[''date''], d[''contents''] end data.sort do |x, y| y.date <=> x.date end end end As you can see, RuberNews is a module which define a News class (a Struct with a couple of convenience methods) and a class method to read the YAML file, create News objects from the entries it contains and sort them from the most recent to the oldest. In case the news file doesn''t exist, is empty or isn''t a valid YAML file, an empty array is returned. Stefano
Damien Pollet
2010-Nov-02 08:05 UTC
[webgen-users] regenerating a page when another file changes
Hi again! So, inspired by this, I hacked together my version :) The idea is that news items go in the metainfo of some page, then there''s a tag to generate a small list of the most recent news. My use-case is for keeping a record of conferences I attended, talks I did, etc, so items will never be longer than a few words or a sentence. Anyway, code is here, comments appreciated: http://github.com/cdlm/website/blob/master/ext/ticker.rb -- Damien Pollet type less, do more [ | ] http://people.untyped.org/damien.pollet