<?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>Rien de grand ne se fit jamais sans enthousiasme.</description>
  <language>en</language>
  <pubDate>Wed, 03 Dec 2008 17:01:33 +0100</pubDate>
  <copyright>2003-2008 &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;code class=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#CC0066; font-weight:bold;&quot;&gt;require&lt;/span&gt; 'yaml'&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color:#9966CC; font-weight:bold;&quot;&gt;class&lt;/span&gt; YAML_to_AR&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color:#9966CC; font-weight:bold;&quot;&gt;def&lt;/span&gt; initialize&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#40;&lt;/span&gt;file, model&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; @data = File.&lt;span style=&quot;color:#CC0066; font-weight:bold;&quot;&gt;open&lt;/span&gt;&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#40;&lt;/span&gt;file&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#123;&lt;/span&gt; |yf| YAML::&lt;span style=&quot;color:#CC0066; font-weight:bold;&quot;&gt;load&lt;/span&gt;&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#40;&lt;/span&gt; yf &lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; @model = model&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color:#9966CC; font-weight:bold;&quot;&gt;end&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color:#9966CC; font-weight:bold;&quot;&gt;def&lt;/span&gt; process&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#40;&lt;/span&gt;data = @data, parent = &lt;span style=&quot;color:#0000FF; font-weight:bold;&quot;&gt;nil&lt;/span&gt;&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color:#9966CC; font-weight:bold;&quot;&gt;if&lt;/span&gt; data.&lt;span style=&quot;color:#9900CC;&quot;&gt;is_a&lt;/span&gt;? &lt;span style=&quot;color:#CC0066; font-weight:bold;&quot;&gt;Array&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; data.&lt;span style=&quot;color:#9900CC;&quot;&gt;each&lt;/span&gt; &lt;span style=&quot;color:#9966CC; font-weight:bold;&quot;&gt;do&lt;/span&gt; |val|&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; process&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#40;&lt;/span&gt;val, parent&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color:#9966CC; font-weight:bold;&quot;&gt;end&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color:#9966CC; font-weight:bold;&quot;&gt;elsif&lt;/span&gt; data.&lt;span style=&quot;color:#9900CC;&quot;&gt;is_a&lt;/span&gt;? Hash&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; data.&lt;span style=&quot;color:#9900CC;&quot;&gt;each&lt;/span&gt; &lt;span style=&quot;color:#9966CC; font-weight:bold;&quot;&gt;do&lt;/span&gt; |key,val|&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; parent = @model.&lt;span style=&quot;color:#9900CC;&quot;&gt;create&lt;/span&gt;&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#40;&lt;/span&gt;:title =&amp;gt; key&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; process&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#40;&lt;/span&gt;val, parent&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color:#9966CC; font-weight:bold;&quot;&gt;end&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color:#9966CC; font-weight:bold;&quot;&gt;elsif&lt;/span&gt; data.&lt;span style=&quot;color:#9900CC;&quot;&gt;is_a&lt;/span&gt;? &lt;span style=&quot;color:#CC0066; font-weight:bold;&quot;&gt;String&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; parent.&lt;span style=&quot;color:#9900CC;&quot;&gt;add_child&lt;/span&gt;&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#40;&lt;/span&gt;@model.&lt;span style=&quot;color:#9900CC;&quot;&gt;create&lt;/span&gt;&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#40;&lt;/span&gt;:title =&amp;gt; data&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color:#9966CC; font-weight:bold;&quot;&gt;end&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color:#9966CC; font-weight:bold;&quot;&gt;end&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&lt;span style=&quot;color:#9966CC; font-weight:bold;&quot;&gt;end&lt;/span&gt;&lt;/code&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;code class=&quot;ruby&quot;&gt;namespace :db &lt;span style=&quot;color:#9966CC; font-weight:bold;&quot;&gt;do&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; desc &lt;span style=&quot;color:#996600;&quot;&gt;&amp;quot;Loads categories defaults data&amp;quot;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; task :load_categories =&amp;gt; :environment &lt;span style=&quot;color:#9966CC; font-weight:bold;&quot;&gt;do&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color:#CC0066; font-weight:bold;&quot;&gt;require&lt;/span&gt; 'lib/yaml_to_ar'&lt;br /&gt;
&amp;nbsp; &amp;nbsp; Category.&lt;span style=&quot;color:#9900CC;&quot;&gt;delete_all&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; categories = YAML_to_AR.&lt;span style=&quot;color:#9900CC;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#40;&lt;/span&gt;'db/categories.&lt;span style=&quot;color:#9900CC;&quot;&gt;yml&lt;/span&gt;', Category&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; categories.&lt;span style=&quot;color:#9900CC;&quot;&gt;process&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color:#9966CC; font-weight:bold;&quot;&gt;end&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color:#9966CC; font-weight:bold;&quot;&gt;end&lt;/span&gt;&lt;/code&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>