<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet title="XSL formatting" type="text/xsl" href="http://mirmodynamics.com/feed/rss2/xslt" ?><rss version="2.0"
  xmlns:dc="http://purl.org/dc/elements/1.1/"
  xmlns:wfw="http://wellformedweb.org/CommentAPI/"
  xmlns:content="http://purl.org/rss/1.0/modules/content/"
  xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
  <title>Mirmo Dynamics - Tag - yaml</title>
  <link>http://mirmodynamics.com/</link>
  <atom:link href="http://mirmodynamics.com/feed/tag/yaml/rss2" rel="self" type="application/rss+xml"/>
  <description>Si tu kiffes pas reunoi, t'écoutes pas et puis c'est tout.</description>
  <language>en</language>
  <pubDate>Sun, 14 Mar 2010 19:59:01 +0100</pubDate>
  <copyright>2003-2009 &amp;copy; Geoffrey Bachelet</copyright>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Dotclear</generator>
  
    
  <item>
    <title>A specific stylesheet for each module</title>
    <link>http://mirmodynamics.com/post/2008/10/15/A-specific-stylesheet-for-each-module</link>
    <guid isPermaLink="false">urn:md5:3d62ec1a3d453aff01166ab7a3582263</guid>
    <pubDate>Wed, 15 Oct 2008 00:43:00 +0200</pubDate>
    <dc:creator>Geoffrey</dc:creator>
        <category>Symfony</category>
        <category>configuration</category><category>css</category><category>stylesheets</category><category>symfony</category><category>tips</category><category>yaml</category>    
    <description>    &lt;p&gt;So this is the first post of the newly opened &lt;a href=&quot;http://mirmodynamics.com/category/symfony&quot;&gt;symfony category&lt;/a&gt; of this blog, and I want to make things clear right now: you (most likely) won't find (yet) any &lt;strong&gt;pro&lt;/strong&gt;tip or high level symfony tutorials here, as I'm still in the process of learning symfony. The good news though is that I'm currently assigned an 1.2-DEV project, so you may get some insight at what's up in the dev branch of the framework (especially regarding sfForm) :-)&lt;/p&gt;


&lt;p&gt;If your are looking for more complete material on the subject, please redirect yourself to &lt;a href=&quot;http://www.symfony-project.org/&quot;&gt;the official website&lt;/a&gt; (where you can find the documentation and a very interesting blog) or &lt;a href=&quot;http://www.aide-de-camp.org/&quot;&gt;Fabien's blog&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;That said, I think it could be interesting to post all the little things I learn everyday that make development with symfony easier for the everyday php developper that you might be if you made it this far into this post ;-)&lt;/p&gt;


&lt;p&gt;Soooo, let's begin the show, with some yaml magic. Yaml I said ? Yaml I said. For those not knowing yet, yaml is the format of choice for symfony's configurations file. So what's the point between configuration files and stylesheets ? Let's say you've got a symfony application (say, frontend), and you'd like a particular module (say, news) in this application to have its own stylesheet in addition of the defaults stylesheets you defined already. Very simple, you start by creating the adequate configuration file:&lt;/p&gt;

&lt;pre&gt;
cd apps/frontend/modules/news/
mkdir config
vi config/view.yml
&lt;/pre&gt;


&lt;p&gt;All you have to do know is declare the stylesheet:&lt;/p&gt;

&lt;pre&gt;
all:
  stylesheets: [news]
&lt;/pre&gt;


&lt;p&gt;And that's all, no helper call in the layout, your &lt;code&gt;news.css&lt;/code&gt; will automagically be appended to the &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt; of your generated html. You can also declare multiples css, or control which actions get a particular css, and even specify to which media they apply:&lt;/p&gt;

&lt;pre&gt;
all:
  stylesheets: [news, news_print: { media: print }]
list:
  stylesheets: [list]
&lt;/pre&gt;


&lt;p&gt;Handy, heh.&lt;/p&gt;


&lt;p&gt;But that's not all ! If you're not that much into yaml, you can use a view helper, directly into your template:&lt;/p&gt;

&lt;pre&gt;
&amp;lt;?php use_stylesheet('news'); ?&amp;gt;
&lt;/pre&gt;


&lt;p&gt;Or even add it from the controller:&lt;/p&gt;

&lt;pre&gt;
&amp;lt;?php $this-&amp;gt;getResponse()-&amp;gt;addStylesheet('news'); ?&amp;gt;
&lt;/pre&gt;</description>
    
    
    
          <comments>http://mirmodynamics.com/post/2008/10/15/A-specific-stylesheet-for-each-module#comment-form</comments>
      <wfw:comment>http://mirmodynamics.com/post/2008/10/15/A-specific-stylesheet-for-each-module#comment-form</wfw:comment>
      <wfw:commentRss>http://mirmodynamics.com/feed/atom/comments/1142</wfw:commentRss>
      </item>
    
  <item>
    <title>yaml, activerecord and acts_as_nested_set</title>
    <link>http://mirmodynamics.com/post/2007/12/02/yaml-activerecord-and-acts_as_nested_set</link>
    <guid isPermaLink="false">urn:md5:8723be74d366c359a8c02a308d5844be</guid>
    <pubDate>Sun, 02 Dec 2007 16:41:00 +0100</pubDate>
    <dc:creator>Geoffrey</dc:creator>
        <category>Coding</category>
        <category>activerecord</category><category>rails</category><category>rake</category><category>ruby</category><category>yaml</category>    
    <description>    &lt;p&gt;I used to use this &lt;a href=&quot;http://thecaribbeanweblog.com/index.php/2007/06/21/150-yaml-et-activerecord-et-sql-plus-generalement&quot;&gt;yaml_to_ar lib&lt;/a&gt; from &lt;a href=&quot;http://thecaribbeanweblog.com/&quot;&gt;christophe&lt;/a&gt; to load categories tree into my database, using &lt;code&gt;&lt;a href=&quot;http://wiki.rubyonrails.org/rails/pages/ActsAsTree&quot;&gt;acts_as_tree&lt;/a&gt;&lt;/code&gt; in the model that was perfect. Arrived the time when I felt the need to use &lt;code&gt;&lt;a href=&quot;http://api.rubyonrails.com/classes/ActiveRecord/Acts/NestedSet/ClassMethods.html&quot;&gt;acts_as_nested_set&lt;/a&gt;&lt;/code&gt; instead, for which I had to fill the &lt;code&gt;lft&lt;/code&gt; and &lt;code&gt;rgt&lt;/code&gt; columns. So I just rewrote the &lt;em&gt;yaml_to_ar&lt;/em&gt; piece of code (put this in &lt;code&gt;lib/yaml_to_ar.rb&lt;/code&gt;):&lt;/p&gt;

&lt;pre&gt;
[ruby]
require 'yaml'

class YAML_to_AR

  def initialize(file, model)
    @data = File.open(file) { |yf| YAML::load( yf ) }
    @model = model
  end

  def process(data = @data, parent = nil)
    if data.is_a? Array
      data.each do |val|
        process(val, parent)
      end
    elsif data.is_a? Hash
      data.each do |key,val|
        parent = @model.create(:title =&amp;gt; key)
        process(val, parent)
      end
    elsif data.is_a? String
      parent.add_child(@model.create(:title =&amp;gt; data))
    end
  end

 end
&lt;/pre&gt;


&lt;p&gt;This should handle both &lt;code&gt;acts_as_tree&lt;/code&gt; and &lt;code&gt;acts_as_nested&lt;/code&gt;. To ease things a bit further, I also wrote a rake task (to drop in &lt;code&gt;lib/tasks/db_load_categories.rake&lt;/code&gt; for example):&lt;/p&gt;

&lt;pre&gt;
[ruby]
namespace :db do
  desc &amp;quot;Loads categories defaults data&amp;quot;
  task :load_categories =&amp;gt; :environment do
    require 'lib/yaml_to_ar'
    Category.delete_all
    categories = YAML_to_AR.new('db/categories.yml', Category)
    categories.process
  end
end
&lt;/pre&gt;


&lt;p&gt;Now I just &lt;code&gt;rake db:load_categories&lt;/code&gt;, and voila !&lt;/p&gt;</description>
    
    
    
          <comments>http://mirmodynamics.com/post/2007/12/02/yaml-activerecord-and-acts_as_nested_set#comment-form</comments>
      <wfw:comment>http://mirmodynamics.com/post/2007/12/02/yaml-activerecord-and-acts_as_nested_set#comment-form</wfw:comment>
      <wfw:commentRss>http://mirmodynamics.com/feed/atom/comments/1077</wfw:commentRss>
      </item>
    
</channel>
</rss>