<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Sean Clark Hess - Posts</title>
	
	<link>http://seanhess.net/</link>
	<description>Code, Business, Tech, and Life from Sean Clark Hess</description>
	
	<!--Fri, 19 Jun 2009 07:28:22 +0000-->
	<pubDate>Wed, 08 Sep 2010 23:57:58 EDT</pubDate><!--  -->
	<generator>Manual</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>

	
<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/seanhess" /><feedburner:info uri="seanhess" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
	<title>Use css to style a custom spark skin in Flex 4</title>
	<link>http://feedproxy.google.com/~r/seanhess/~3/E_D1MO6lkTU/flex_skins_and_styles</link>
	<!--<comments>http://codearchive.seanhess.net/?p=225#comments</comments>-->
	<pubDate>Fri, 06 Nov 2009 16:51:53 EST</pubDate><!-- Fri, 19 Jun 2009 07:27:52 +0000 -->
	<dc:creator>sean</dc:creator>
	
	
		<category><![CDATA[Flex]]></category>
	
		<category><![CDATA[Spark]]></category>
	
		<category><![CDATA[Tutorial]]></category>
	
	
	<guid isPermaLink="false">http://seanhess.net/posts/flex_skins_and_styles</guid>
	<description><![CDATA[ I&#8217;ve finally had a chance to dive in to Flex 4. One trick I learned is incredibly powerful. CSS is a powerful way to specify settings to something from the outside, but it quickly becomes a pain if you need to push pixels around. I&#8217;m going to show you how you can create a skin that reads]]></description>
	<content:encoded><![CDATA[<p>I&#8217;ve finally had a chance to dive in to Flex 4. One trick I learned is incredibly powerful. CSS is a powerful way to specify settings to something from the outside, but it quickly becomes a pain if you need to push pixels around. I&#8217;m going to show you how you can create a skin that reads its properties from a stylesheet. This allows css to do what it does best: set simple properties, and lets you do the pixel pushing in the Skin.</p>

<p>Let&#8217;s start with some Flex 3 code we&#8217;d like to duplicate. This will create a &#8220;modal&#8221; overlay that covers the app with a translucent screen. You might use this for a LightBox.</p>

<pre><code>&lt;!-- MyOverlay.mxml --&gt;
&lt;mx:Canvas 
    width=&quot;100%&quot; height=&quot;100%&quot;
    styleName=&quot;overlay&quot;
    &gt;

    &lt;!-- Put a panel or something here --&gt;

&lt;/mx:Canvas&gt;

/** styles.css **/
.overlay {
    background-color: #000000;
    background-alpha: 0.7;
}</code></pre>

<h2 id='our_first_skin'>Our First Skin</h2>

<p>We want to create this in Flex 4. The (rough) equivalent to canvas is a <code>Group</code>, but it isn&#8217;t skinnable, so we can use a <code>SkinnableContainer</code> instead.</p>

<pre><code>&lt;!-- MyOverlay.mxml --&gt;
&lt;s:SkinnableContainer
    width=&quot;100%&quot; height=&quot;100%&quot;
    skinName=&quot;overlay&quot;
    &gt;

    &lt;!-- Stuff --&gt;

&lt;/s:SkinnableContainer&gt; </code></pre>

<p>SkinnableContainer doesn&#8217;t have a way to set backgroundColor or backgroundAlpha! The css will not work.</p>

<p>Let&#8217;s create the same functionality in a skin instead.</p>

<pre><code>&lt;!-- skins/OverlaySkin.mxml --&gt;
&lt;s:SparkSkin ... &gt;

    &lt;!-- The highest-level base class that can use this--&gt;
    &lt;fx:Metadata&gt;
        [HostComponent(&quot;spark.components.SkinnableContainer&quot;)]
    &lt;/fx:Metadata&gt;
    
    &lt;!-- specify all the states the host component uses --&gt;
    &lt;s:states&gt;
        &lt;s:State name=&quot;normal&quot;/&gt;
        &lt;s:State name=&quot;disabled&quot;/&gt;
    &lt;/s:states&gt;
    
    &lt;!-- Here&#39;s our overlay! --&gt;
    &lt;s:Rect left=&quot;0&quot; right=&quot;0&quot; top=&quot;0&quot; bottom=&quot;0&quot;&gt;
        &lt;s:fill&gt;
            &lt;s:SolidColor color=&quot;#000000&quot; alpha=&quot;0.7&quot;/&gt;
        &lt;/s:fill&gt;
    &lt;/s:Rect&gt;
    
    &lt;!-- Put the panel, or whatever is in the component here --&gt; 
    &lt;s:Group id=&quot;contentGroup&quot; verticalCenter=&quot;0&quot; horizontalCenter=&quot;0&quot;&gt;
        &lt;s:layout&gt;&lt;s:BasicLayout/&gt;&lt;/s:layout&gt;
    &lt;/s:Group&gt;
    
&lt;/s:SparkSkin&gt; </code></pre>

<p>That&#8217;s not too bad. We have a skin, and now we can apply it to our component by setting the <code>skinClass</code> property. For example:</p>

<pre><code>&lt;!-- MyOverlay.mxml --&gt;
&lt;s:SkinnableContainer
    width=&quot;100%&quot; height=&quot;100%&quot;
    skinClass=&quot;skins.OverlaySkin&quot;
    &gt;

    &lt;!-- content --&gt;

&lt;/s:SkinnableContainer&gt;</code></pre>

<p>Or we can set the skinClass in the style.</p>

<pre><code>&lt;!-- MyOverlay.mxml --&gt;
&lt;s:SkinnableContainer
    width=&quot;100%&quot; height=&quot;100%&quot;
    styleName=&quot;overlay&quot; 
    &gt;

    &lt;!-- content --&gt;

&lt;/s:SkinnableContainer&gt;

/** styles.css **/
.overlay {
    skinClass: ClassReference(&quot;skins.OverlaySkin&quot;);
}</code></pre>

<h2 id='using_css_on_the_skin'>Using CSS on the Skin</h2>

<p>Now we have a styleName we can apply to any SkinnableContainer and it will make it look like our black, translucent overlay. This works great, so we start using it, but pretty soon we realize that we need to be able to add a background to another container, but we don&#8217;t want to create a new skin just to tweak the color and alpha. Here is where it gets fun. We change the <code>Rect</code> tag in our skin to look like this:</p>

<pre><code>&lt;s:Rect left=&quot;0&quot; right=&quot;0&quot; top=&quot;0&quot; bottom=&quot;0&quot;&gt;
	&lt;s:fill&gt;
		&lt;s:SolidColor color=&quot;{getStyle(&#39;backgroundColor&#39;)}&quot; alpha=&quot;{getStyle(&#39;backgroundAlpha&#39;)}&quot;/&gt;
	&lt;/s:fill&gt;
&lt;/s:Rect&gt;</code></pre>

<p>Now it will get it&#8217;s color and alpha from the style. We can change our overlay style to look like this</p>

<pre><code>/** styles.css **/
.overlay {
    background-color: #000000;
    background-alpha: 0.7;
    skinClass: ClassReference(&quot;skins.OverlaySkin&quot;);
}</code></pre>

<p>That looks a lot more like the Flex 3 version! We can then add more styles for other kinds of containers that need backgrounds, and our skin is now much more useful than before.</p>

<h2 id='the_final_version'>The Final Version</h2>

<pre><code>&lt;!-- skins/BackgroundSkin.mxml --&gt;
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:SparkSkin xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot; 
             xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot; 
             xmlns:mx=&quot;library://ns.adobe.com/flex/halo&quot;&gt;
    
    &lt;fx:Metadata&gt;
        [HostComponent(&quot;spark.components.SkinnableContainer&quot;)]
    &lt;/fx:Metadata&gt;
    
    
    &lt;s:states&gt;
        &lt;s:State name=&quot;normal&quot;/&gt;
        &lt;s:State name=&quot;disabled&quot;/&gt;
    &lt;/s:states&gt;
    
    &lt;s:Rect left=&quot;0&quot; right=&quot;0&quot; top=&quot;0&quot; bottom=&quot;0&quot;&gt;
        &lt;s:fill&gt;
            &lt;s:SolidColor color=&quot;{getStyle(&#39;backgroundColor&#39;)}&quot; alpha=&quot;{getStyle(&#39;backgroundAlpha&#39;)}&quot;/&gt;
        &lt;/s:fill&gt;
    &lt;/s:Rect&gt;
    
    &lt;!-- Tells the skin where to put the children you have specified --&gt;
    &lt;s:Group id=&quot;contentGroup&quot; verticalCenter=&quot;0&quot; horizontalCenter=&quot;0&quot;&gt;
        &lt;s:layout&gt;&lt;s:BasicLayout/&gt;&lt;/s:layout&gt;
    &lt;/s:Group&gt;
    
&lt;/s:SparkSkin&gt;

/** styles.css **/
.overlay {
    background-color: #000000;
    background-alpha: 0.7;
    skinClass: ClassReference(&quot;skins.OverlaySkin&quot;);
}

.error {
    background-color: #FF0000;
    background-alpha: 1.0;
}

.success {
    background-color: #00FF00;
    background-alpha: 1.0;
}</code></pre>

<p>Using this technique will allow you to play to the strengths of both CSS and Spark Skins.</p><img src="http://feeds.feedburner.com/~r/seanhess/~4/E_D1MO6lkTU" height="1" width="1"/>]]></content:encoded>
	<!--<wfw:commentRss>http://codearchive.seanhess.net/?feed=rss2&amp;p=225</wfw:commentRss>-->
<feedburner:origLink>http://seanhess.net/posts/flex_skins_and_styles</feedburner:origLink></item>

<item>
	<title>FlashLib Library Index Features</title>
	<link>http://feedproxy.google.com/~r/seanhess/~3/AUSgYeKz3WA/flashlib_planned_features</link>
	<!--<comments>http://codearchive.seanhess.net/?p=225#comments</comments>-->
	<pubDate>Wed, 26 Aug 2009 11:12:24 EDT</pubDate><!-- Fri, 19 Jun 2009 07:27:52 +0000 -->
	<dc:creator>sean</dc:creator>
	
	
		<category><![CDATA[Flex]]></category>
	
		<category><![CDATA[Framework]]></category>
	
		<category><![CDATA[FlashLib]]></category>
	
	
	<guid isPermaLink="false">http://seanhess.net/posts/flashlib_planned_features</guid>
	<description><![CDATA[ In   An Army of Small Libraries   I suggested creating a site that indexes every known bit of reusable Actionscript code in existence.  FlashLib.org  is up, and I&#8217;d like to solicit feedback on the planned features as it progresses. Please look over these and let me know what you think.      Fl]]></description>
	<content:encoded><![CDATA[<p>In <a href='/posts/an_army_of_small_libraries'><em>An Army of Small Libraries</em></a> I suggested creating a site that indexes every known bit of reusable Actionscript code in existence. <a href='http://flashlib.org'>FlashLib.org</a> is up, and I&#8217;d like to solicit feedback on the planned features as it progresses. Please look over these and let me know what you think.</p>

<p class='download'> <a href='http://flashlib.org'>FlashLib.org</a> <a href='http://flashlib.uservoice.com/pages/26908-general?lang=en&amp;utm_campaign=Widgets&amp;utm_content=tab-widget&amp;utm_medium=widget&amp;utm_source=flashlib.uservoice.com' title='User Voice'>Suggestions</a> <a href='http://github.com/seanhess/flashlib/tree' title='Site Source'>Source</a></p>

<h2 id='basic_features'>Basic Features</h2>
<div class='subblock'>
    <h3>Projects</h3>
    <p>Users will create project pages which contain information about a particular project. A project can be anything from an MVC framework to a simple code sample</p>
</div><div class='subblock'>
    <h3>Index</h3>
    <p>Users can see a list of projects sorted by popularity or freshness in any list</p>
</div><div class='subblock'>
    <h3>Tags</h3>
    <p>Users can add custom tags to any project. They can see all the projects in a particular category</p>
</div><div class='subblock'>
    <h3>Search</h3>
    <p>Users can search by title and tag</p>
</div><div class='subblock'>
    <h3>Builds</h3>
    <p>Users can create groups of projects to download all at once from their favorites.</p>
</div><div class='subblock'>
    <h3>Reputation / Voting</h3>
    <p>Users build reputation that gives them more rights on the site</p>
</div>
<h2 id='project_page_features'>Project Page Features</h2>
<div class='subblock'>
    <h3>Home Page</h3>
    <p>Link to project home page or blog post</p>
</div><div class='subblock'>
    <h3>Similar Projects</h3>
    <p>Anyone can submit a link to another project in the system. It prominently shows all similar projects ranked by score.</p>
</div><div class='subblock'>
    <h3>Repo</h3>
    <p>Optional Link to GitHub or Google Code repo</p>
</div><div class='subblock'>
    <h3>Access</h3>
    <p>Page is editable by anyone with enough reputation</p>
</div><div class='subblock'>
    <h3>Reviews</h3>
    <p>Anyone can write reviews or link to external reviews of a project</p>
</div><div class='subblock'>
    <h3>Resources</h3>
    <p>Anyone can post links to tutorials, documentation, or anything else about the project</p>
</div>
<h2 id='faq'>FAQ</h2>

<h4 id='how_can_i_help'>How can I help?</h4>

<p>Make suggestions on <a href='http://flashlib.uservoice.com/pages/26908-general?lang=en&amp;utm_campaign=Widgets&amp;utm_content=tab-widget&amp;utm_medium=widget&amp;utm_source=flashlib.uservoice.com' title='User Voice'>UserVoice</a>. Follow me on <a href='http://twitter.com/seanhess'>twitter</a> or subscribe to the <a href='http://feeds.feedburner.com/seanhess'>blog feed</a> for updates.</p>

<p>Please <a href='/about'>contact me</a> if you&#8217;d like to help code up the site. You can also watch or fork the <a href='http://github.com/seanhess/flashlib/tree' title='Site Source'>GitHub Repository</a>. All of the site&#8217;s code will be public, so it should be easy to contribute. If you have something to submit, just contact me and I&#8217;ll pull from your fork.</p>

<h4 id='what_about_osflashorg'>What about OSFlash.org?</h4>

<p>OSFlash.org only lists <em>major</em> projects. FlashLib will index tiny blog posts as well. FlashLib will also add all the spiffy democratic features</p>

<h4 id='what_about_riaforgeorg'>What about RIAForge.org?</h4>

<p>RIAForge requires that projects be hosted with them. While they have a lot of good stuff there, they are missing many important things. We will use links to project pages instead of hosting.</p>

<h4 id='what_about_github'>What about GitHub?</h4>

<p>We will link to GitHub projects. Not only does GitHub not provide all the features we need, but it locks people into git, and many projects are on SVN or just a blog post.</p>

<h4 id='what_about_google_code__svn__some_other_repo_thing'>What about Google Code / SVN / Some other Repo thing?</h4>

<p>Remember, we&#8217;re only linking to projects in other places, so we can link to ALL of them.</p>

<h4 id='i_have_a_great_idea_how_can_i_suggest_it'>I have a great idea, how can I suggest it?</h4>

<p>Please visit the <a href='http://flashlib.uservoice.com/pages/26908-general?lang=en&amp;utm_campaign=Widgets&amp;utm_content=tab-widget&amp;utm_medium=widget&amp;utm_source=flashlib.uservoice.com' title='User Voice'>UserVoice</a> page and create the suggestion. Vote on others too!</p>

<h4 id='what_if_two_people_use_the_same_name_or_package'>What if two people use the same name or package?</h4>

<p>This will generally not be a problem, but a simple email to the project author should be enough to get him to make his package names unique. Project names don&#8217;t have to be unique, but moderators can combine them if they are really the same project</p>

<h4 id='can_i_download_a_big_library_with_all_my_favorite_classes'>Can I download a big library with all my favorite classes?</h4>

<p>No. This is a bad idea. It makes more sense to download the swcs for each library separately. However, see the &#8220;Build&#8221; feature above.</p>

<h4 id='what_about_dependencies'>What about dependencies?</h4>

<p>First, dependencies are rare across libraries. However, libraries can easily include another library inside them. Flash knows how to handle it already. I assume this question stems from the desire to create an ActionScript library with a bunch of useful stuff inside that builds on itself. People can still create such libraries. They would be indexed as one project in flashlib. They can also split something like that out into several libraries. Either way it will work.</p>

<h4 id='why_not_just_use_jefferys_underware'>Why not just use Jeffery&#8217;s Underware?</h4>

<p><a href='http://toolbox.protohq.com/underware'>Jeffery has created a great tool here</a>, but it concentrates on downloading the latest code, not discovering it. It also is locked in to SVN.</p>

<h4 id='why_not_just_use_a_wiki'>Why not just use a wiki?</h4>

<p>Wikis are cool, but they do a poor job filtering and sorting information. This will be much like a wiki, but will have extra features.</p><img src="http://feeds.feedburner.com/~r/seanhess/~4/AUSgYeKz3WA" height="1" width="1"/>]]></content:encoded>
	<!--<wfw:commentRss>http://codearchive.seanhess.net/?feed=rss2&amp;p=225</wfw:commentRss>-->
<feedburner:origLink>http://seanhess.net/posts/flashlib_planned_features</feedburner:origLink></item>

<item>
	<title>An Army of Small Libraries</title>
	<link>http://feedproxy.google.com/~r/seanhess/~3/Cx_z4dZrDo4/an_army_of_small_libraries</link>
	<!--<comments>http://codearchive.seanhess.net/?p=225#comments</comments>-->
	<pubDate>Thu, 20 Aug 2009 10:43:13 EDT</pubDate><!-- Fri, 19 Jun 2009 07:27:52 +0000 -->
	<dc:creator>sean</dc:creator>
	
	
		<category><![CDATA[Thoughts]]></category>
	
		<category><![CDATA[Framework]]></category>
	
		<category><![CDATA[Flex]]></category>
	
		<category><![CDATA[FlashLib]]></category>
	
	
	<guid isPermaLink="false">http://seanhess.net/posts/an_army_of_small_libraries</guid>
	<description><![CDATA[ Ted Patrick, known on twitter as  @adobeted , recently released two interesting as3 libraries:  FDOT  and  Tubes . This is not unique to Ted. People constantly develop amazing solutions to common problems. The problem is that it is hard to find these solutions. Unless the developer already has a lar]]></description>
	<content:encoded><![CDATA[<p>Ted Patrick, known on twitter as <a href='http://twitter.com/adobeted'>@adobeted</a>, recently released two interesting as3 libraries: <a href='http://onflash.org/ted/2009/08/fdot-making-hard-things-easier.php' title='FDOT'>FDOT</a> and <a href='http://onflash.org/ted/2009/08/in-app-messaging-with-tubes.php' title='Tubes'>Tubes</a>. This is not unique to Ted. People constantly develop amazing solutions to common problems. The problem is that it is hard to find these solutions. Unless the developer already has a large following, his code usually dies in obscurity. Someone facing a common problem will either develop their own solution, or find a stale solution on google. Ted has been proposing that someone create a standard as3 library. I would like to recommend an alternative.</p>

<p><strong>Update</strong> - <a href='http://flashlib.org'>I&#8217;ve begun work on this at flashlib.org</a></p>

<p><strong>Update</strong> - <a href='/posts/flashlib_planned_features'>I&#8217;ve listed the planned features and made a FAQ page</a></p>

<h2 id='the_standard_library'>The Standard Library</h2>

<p>As far as I understand, Ted means someone should create one swc file containing many classes to solve a wide variety of problems. The advantages of this approach are that people can download the library and use the best solutions available without having to hunt around.</p>

<p>There are several disadvantages, though.</p>

<ol>
<li>
<p><em>The library will grow stale</em> because the maintainers don&#8217;t have an infinite amount of time to check out new stuff. It will have momentum at first, but will become less relevant over time.</p>
</li>

<li>
<p><em>Many good ideas will not be included.</em> The library can only include robust solutions, preventing one person from beginning something and another finishing it. Someone unknown may have a good solution that never gets in because it doesn&#8217;t quite meet standards.</p>
</li>
</ol>

<h2 id='a_better_approach'>A Better Approach</h2>

<p>The monolithic library is a temptation that should be avoided. A better approach is to keep libraries focused and small. This makes it easier to mix and match solutions to exactly fit your project&#8217;s needs.</p>

<p>However, we still need a way to find these small solutions. <em>I propose a community site dedicated to finding good libraries and classes</em>. At first glance, I think it should have the following features.</p>

<ol>
<li>
<p>Links to projects rather than hosting them</p>
</li>

<li>
<p>List of alternative projects</p>
</li>

<li>
<p>Ratings and comments</p>
</li>

<li>
<p>Community editable project pages</p>
</li>

<li>
<p>Reputation System</p>
</li>
</ol>

<p>This will solve the same problems without the disadvantages. With a democratic approach, the very best will naturally rise to the top, people can extend each other&#8217;s work, and the authors don&#8217;t even need to directly participate for it to be effective.</p>

<p>If this idea gains enough steam, I volunteer to create the site. What do you think? What other features should it have?</p><img src="http://feeds.feedburner.com/~r/seanhess/~4/Cx_z4dZrDo4" height="1" width="1"/>]]></content:encoded>
	<!--<wfw:commentRss>http://codearchive.seanhess.net/?feed=rss2&amp;p=225</wfw:commentRss>-->
<feedburner:origLink>http://seanhess.net/posts/an_army_of_small_libraries</feedburner:origLink></item>

<item>
	<title>Client-Side Flex Logging with Shared Object</title>
	<link>http://feedproxy.google.com/~r/seanhess/~3/9zIa_nLR3pk/flex_logging_with_flog</link>
	<!--<comments>http://codearchive.seanhess.net/?p=225#comments</comments>-->
	<pubDate>Tue, 11 Aug 2009 00:00:00 EDT</pubDate><!-- Fri, 19 Jun 2009 07:27:52 +0000 -->
	<dc:creator>sean</dc:creator>
	
	
		<category><![CDATA[Framework]]></category>
	
		<category><![CDATA[Flex]]></category>
	
	
	<guid isPermaLink="false">http://seanhess.net/posts/flex_logging_with_flog</guid>
	<description><![CDATA[ Having your app keep a detailed log can be indispensable for figuring out tricky user-reported bugs. This is easy on the server-side, where you can use any logging framework or just write to a file. Flash includes the  trace  function, which is useful while developing, but nearly impossible to get f]]></description>
	<content:encoded><![CDATA[<p>Having your app keep a detailed log can be indispensable for figuring out tricky user-reported bugs. This is easy on the server-side, where you can use any logging framework or just write to a file. Flash includes the <code>trace</code> function, which is useful while developing, but nearly impossible to get from an end-user. <a href='http://livedocs.adobe.com/flex/3/html/help.html?content=logging_09.html' title='Flex Loggin API'>Flex, however, has a good logging api</a> that lets you put log statements anywhere you want. I&#8217;ve always wanted the interface to be as easy as <code>trace</code>, so I write a couple of scripts to make it easier.</p>

<p class='download'> <a href='http://github.com/seanhess/flog' title='Flog - Flex Logging'>Flog (Flex Logging) on Github</a> <a href='http://github.com/seanhess/flog/tree/master/source/src/net/seanhess/flog/log.as'>log.as</a> <a href='http://github.com/seanhess/flog/tree/master/source/src/net/seanhess/flog/SharedObjectTarget.as'>SharedObjectTarget.as</a></p>

<p>There are two files in there now. The first is <code>log.as</code>. I didn&#8217;t realize before that it was possible to define your own package-level functions. Some might disagree with me, but I think this syntax is a lot nicer than the default. It looks just like trace. All it does is create an easy way to access the flex logging api.</p>

<pre><code>import net.seanhess.flog.log;

function stuff():void
{
    log(&quot;Executing stuff&quot;);
    // do stuff 
    log(&quot;Finished!&quot;);
}</code></pre>

<p>You can replace all your trace statements with these. It&#8217;s easy enough to add a trace target to the logging api, so all log messages are traced. See the <a href='http://livedocs.adobe.com/flex/3/html/help.html?content=logging_09.html' title='Flex Loggin API'>Flex Logging API</a> for more details, but here&#8217;s how you would do it.</p>

<pre><code>import mx.logging.Log;
import mx.logging.targets.TraceTarget;

// Only once in your app
function addLoggingTargets():void
{
    Log.addTarget(new TraceTarget());
}</code></pre>

<p>The second little tool is a new logging target. I wanted a way to log to a local file in flex, so the support guys could get an end-user to email it. The only way to do this without hacks is to write to a shared object. It turns out if you write an array of strings to a shared object, it&#8217;s easily human-readable. You attach <code>SharedObjectTarget</code> like any other target and away you go.</p>

<pre><code>import mx.logging.Log;
import net.seanhess.flog.SharedObjectTarget;

// Only once in your app
function addLoggingTargets():void
{
    Log.addTarget(new TraceTarget());
    Log.addTarget(new SharedObjectTarget(&quot;MyCustomAppLogging&quot;));        
}</code></pre>

<p>The file is located in the application data folder, which is in <code>~/Library/Preferences/Macromedia/Flash Player/#SharedObjects</code> on the mac. (Google it for windows). The target does some fancy stuff like automatically saving if it hasn&#8217;t received a log message for one second. It also automatically rotates messages once the size reaches about 50k (The default allowed size for shared objects is 100k).</p>

<p>There&#8217;s more that can be done here. I might add a <code>debug</code> and an <code>error</code> function. You could easily write an app to send the contents to a server too.</p>

<p>For alternatives and more information look at the approaches of <a href='http://www.insideria.com/2009/08/client-side-error-logging-arch.html' title='Client side error logging'>Tom Barker</a>, <a href='http://www.flexer.info/2007/10/24/debuglogging-client-side/' title='Debugging Logging Client-side'>Virgil Cristea</a>, and <a href='http://johnwilker.com/2006/11/Flex_Logging_Framework/'>John Wilker</a>.</p><img src="http://feeds.feedburner.com/~r/seanhess/~4/9zIa_nLR3pk" height="1" width="1"/>]]></content:encoded>
	<!--<wfw:commentRss>http://codearchive.seanhess.net/?feed=rss2&amp;p=225</wfw:commentRss>-->
<feedburner:origLink>http://seanhess.net/posts/flex_logging_with_flog</feedburner:origLink></item>

<item>
	<title>How to write your own PHP templating engine</title>
	<link>http://feedproxy.google.com/~r/seanhess/~3/XjqKG8Dl5EU/simple_templating_system_in_php</link>
	<!--<comments>http://codearchive.seanhess.net/?p=225#comments</comments>-->
	<pubDate>Mon, 03 Aug 2009 00:00:00 EDT</pubDate><!-- Fri, 19 Jun 2009 07:27:52 +0000 -->
	<dc:creator>sean</dc:creator>
	
	
		<category><![CDATA[Framework]]></category>
	
		<category><![CDATA[PHP]]></category>
	
		<category><![CDATA[Tutorial]]></category>
	
	
	<guid isPermaLink="false">http://seanhess.net/posts/simple_templating_system_in_php</guid>
	<description><![CDATA[ MVC is all the rage. Choosing a framework, however, is not so easy. The  view  part of a standard php MVC framework usually involves grabbing one or more  model  objects and printing out some text (html) about them.  There are several frameworks that do this, including the famous smarty.  There are ]]></description>
	<content:encoded><![CDATA[<p>MVC is all the rage. Choosing a framework, however, is not so easy. The <code>view</code> part of a standard php MVC framework usually involves grabbing one or more <code>model</code> objects and printing out some text (html) about them. <a href='http://www.dreamcss.com/2009/07/11-interesting-php-template-engines.html' title='11 PHP Templating Engines'>There are several frameworks that do this, including the famous smarty.</a> There are even more frameworks, like <a href='http://framework.zend.com/'>Zend</a> and <a href='http://cakephp.org/'>CakePHP</a> that include templating as a subset of what they do.</p>

<p><em>You may not have realized that PHP is itself a templating engine.</em> It allows you to intersperse logic and text, and has some handy features to make it easy. I&#8217;m going to show you how to build a php-based templating framework in one file.</p>

<p>Please read <a href='http://www.massassi.com/php/articles/template_engines/' title='Talks all about them and talks you through it'>Template Engines</a> and <a href='http://www.sitepoint.com/article/beyond-template-engine/' title='Beyond Template Engine'>Beyond Template Engine</a> for background and other approaches to the same thing. They specifically address why you would want to use PHP instead of another layer for templating.</p>

<h2 id='the_final_product'>The final product</h2>

<p class='download'> <a href='http://codesamples.seanhess.net/SimpleTemplate.php'>SimpleTemplate.php</a></p>

<p><em>post.php?id=2</em></p>

<pre><code>&lt;?php

    require_once(&#39;SimpleTemplate.php&#39;);

    $post = new BlogPost($_GET[&quot;id&quot;]); // pretend we&#39;re fetching a post from a db
    $main = new SimpleTemplate(&quot;templating/post_full.php&quot;);
    $main-&gt;post = $post;
    $main-&gt;comments = $post-&gt;comments;

    $layout = new SimpleTemplate(&quot;templating/main_layout.php&quot;);
    $layout-&gt;title = &quot;Post - $post-&gt;title&quot;;
    $layout-&gt;content = $main-&gt;run();

    echo $layout;</code></pre>

<p><em>templating/post_full.php</em></p>

<pre><code>&lt;h2&gt;&lt;?= $post-&gt;title ?&gt;&lt;/h2&gt;
&lt;p&gt;&lt;?= $post-&gt;body ?&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;? foreach ($comments as $comment): ?&gt;
&lt;p&gt;Comment - &lt;?= &quot;$comment-&gt;name - $comment-text&quot; ?&gt;&lt;/p&gt;
&lt;? endforeach; ?&gt;
&lt;!-- Add a comment form here --&gt;</code></pre>

<p><em>templating/main_layout.php</em></p>

<pre><code>&lt;html&gt;
&lt;head&gt;
    &lt;!-- some script tags, css, etc --&gt;
    &lt;title&gt;&lt;?= $title ?&gt;&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;h1&gt;This is my site&lt;/h1&gt;
    &lt;?= $content ?&gt;
&lt;/body&gt;
&lt;/html&gt;</code></pre>

<p>It&#8217;s simple to use, and requires nothing but basic php skills (maybe with the addition of knowing you can do that colon trick with loops).</p>

<h2 id='how_to_make_one'>How to make one?</h2>

<p>It&#8217;s simple, really. First let&#8217;s create the class, and add 3 fields. <code>source</code> will store the variables, <code>path</code> is the path to the template, and <code>result</code> contains the generated result.</p>

<pre><code>class SimpleTemplate
{
    public $source;
    public $path;
    public $result;
}</code></pre>

<p>The main essential feature is that the engine include another php script and capture its output. You can easily do that with <a href='http://us2.php.net/manual/en/ref.outcontrol.php' title='PHP Output Buffer'>php&#8217;s output buffer functions</a>. Let&#8217;s create a &#8220;run&#8221; function that will return the template&#8217;s content. Anything <code>print</code>ed or <code>echo</code>ed between <code>ob_start()</code> and <code>ob_get_contents()</code> will be stored in <code>$this-&gt;result</code>.</p>

<pre><code>public function run()
{
    ob_start();                         
    extract ($this-&gt;source); 
    include $this-&gt;path;
    $this-&gt;result = ob_get_contents();
    ob_end_clean();
    return $this-&gt;result;
}</code></pre>

<p>Next we need a way to store some variables so that <code>extract</code> call works. <code>extract</code> takes the variables available in a certain scope and empties them into the current scope. So, we can set <code>$template-&gt;title = &quot;a title&quot;;</code> and that variable will be available in our template as <code>$title</code>. We&#8217;ll implement php&#8217;s magic <code>__set()</code> and <code>__get()</code> to do this.</p>

<pre><code>public function __set($name, $value)
{
    $this-&gt;source[$name] = $value;
}

public function __get($name)
{
    return isset($this-&gt;source[$name]) ? $this-&gt;source[$name] : &quot;&quot;;
}</code></pre>

<p>Now that extract call will work as explained above. Finally, let&#8217;s add a <code>__toString()</code> method so we can just <code>print $template;</code> and use string concatenation and go nuts. Let&#8217;s also add a constructor that stores the <code>$path</code> variable.</p>

<pre><code>&lt;?php

class SimpleTemplate
{
    public $source;
    public $path;
    public $result;

    public function SimpleTemplate($path=false)
    {
        $this-&gt;source = array();
        $this-&gt;path($path);
    }

    public function __toString()
    {
        return $this-&gt;run();
    }

    public function __set($name, $value)
    {
        $this-&gt;source[$name] = $value;
    }

    public function __get($name)
    {
        return isset($this-&gt;source[$name]) ? $this-&gt;source[$name] : &quot;&quot;;
    }

    public function run()
    {
        ob_start();
        extract ($this-&gt;source);
        include $this-&gt;path;
        $this-&gt;result = ob_get_contents();
        ob_end_clean();
        return $this-&gt;result;
    }
}</code></pre>

<p>You can get more fancy if you like. In the full example I added <em>parents</em> for templates, meaning they can access variables from their parent&#8217;s scope. I also added the <code>extract</code> method, which copies all the variables in an object into the scope (it saves a few characters).</p><img src="http://feeds.feedburner.com/~r/seanhess/~4/XjqKG8Dl5EU" height="1" width="1"/>]]></content:encoded>
	<!--<wfw:commentRss>http://codearchive.seanhess.net/?feed=rss2&amp;p=225</wfw:commentRss>-->
<feedburner:origLink>http://seanhess.net/posts/simple_templating_system_in_php</feedburner:origLink></item>

<item>
	<title>Easy Daemons in PHP</title>
	<link>http://feedproxy.google.com/~r/seanhess/~3/2U-aGp7zMFY/easy_daemons_in_php</link>
	<!--<comments>http://codearchive.seanhess.net/?p=225#comments</comments>-->
	<pubDate>Mon, 03 Aug 2009 00:00:00 EDT</pubDate><!-- Fri, 19 Jun 2009 07:27:52 +0000 -->
	<dc:creator>sean</dc:creator>
	
	
		<category><![CDATA[PHP]]></category>
	
		<category><![CDATA[Component]]></category>
	
	
	<guid isPermaLink="false">http://seanhess.net/posts/easy_daemons_in_php</guid>
	<description><![CDATA[ This class and script makes it easy to turn a one-shot php script into a daemon that runs in the background on a timer. This is good for things you want to happen infrequently. For example, your site may need to use curl to fetch several different rss feeds, combining them into one feed. You don&#82]]></description>
	<content:encoded><![CDATA[<p>This class and script makes it easy to turn a one-shot php script into a daemon that runs in the background on a timer. This is good for things you want to happen infrequently. For example, your site may need to use curl to fetch several different rss feeds, combining them into one feed. You don&#8217;t want to fetch all the feeds every time someone asks for the combined one. It is better to generate the combined feed every 5 minutes or so.</p>

<p class='download'> <a href='http://files.seanhess.net/code/daemons.zip'>Daemon source files</a></p>

<pre><code>daemon generate_feed.php start
daemon generate_feed.php stop     
daemon generate_feed.php restart</code></pre>

<p>generate_feed.php might look like this</p>

<pre><code>require_once(&quot;BlogDatabase.php&quot;);
echo &quot;Generating Feed&quot;; // this will go to the log  

$data = new BlogDatabase();
$posts = $data-&gt;getAllNewPosts();

foreach($posts as $post)
{
    // generate an rss feed
}                          

file_put_contents(&quot;feed.xml&quot;, $contents);</code></pre>

<h2 id='alternatives'>Alternatives</h2>

<ul>
<li>
<p><em>crontab</em> - This is the easiest way to get a script to run on a timer, but there are a few disadvantages. Specifically, you don&#8217;t have exact control over the timer, nor can you prevent the script from running if the system isn&#8217;t ready. <a href='http://kevin.vanzonneveld.net/techblog/article/create_daemons_in_php/' title='Create Daemons in PHP'>Refer to this article for more information.</a></p>
</li>

<li>
<p><em>System_Daemon</em> - This was built using <code>System_Daemon</code>. I created this because my daemons were behaving strangely. Our database calls weren&#8217;t working properly, and things were just generally messed up.</p>
</li>
</ul>

<h2 id='what_it_does'>What it does</h2>

<p>This uses the pear <code>System_Daemon</code> to create a daemon that runs your script every 5 seconds (by default). It uses shell_exec to run it, giving you the following advantages.</p>

<ul>
<li>
<p>Your script runs in a &#8220;sandboxed&#8221; environment. You don&#8217;t have to worry about stale variables or strange processes making your code behave strangely.</p>
</li>

<li>
<p>You can test your script by running it on the command-line, since this is exactly what the daemon does.</p>
</li>

<li>
<p>You can easily start and stop the daemon using the included tool.</p>
</li>

<li>
<p>It puts output from the script into the daemon&#8217;s log (<code>/var/log/generate_feed.log</code> on my system)</p>
</li>
</ul>

<p>Sorry it isn&#8217;t more flexible right now, but the timer can be easily changed in <code>Daemon.php</code></p>

<h2 id='installation'>Installation</h2>

<p>You need to install the pear <code>System_Daemon</code> module. Refer to <a href='http://kevin.vanzonneveld.net/techblog/article/create_daemons_in_php/' title='Create Daemons in PHP'>this article</a> for instructions.</p>

<p>Put your daemons in the same folder as these scripts, or else make sure <code>Daemon.php</code> is in your include path when you run <code>daemon</code> from the command line.</p><img src="http://feeds.feedburner.com/~r/seanhess/~4/2U-aGp7zMFY" height="1" width="1"/>]]></content:encoded>
	<!--<wfw:commentRss>http://codearchive.seanhess.net/?feed=rss2&amp;p=225</wfw:commentRss>-->
<feedburner:origLink>http://seanhess.net/posts/easy_daemons_in_php</feedburner:origLink></item>

<item>
	<title>Create a Blog in Ruby and Sinatra - Part 2 - Models</title>
	<link>http://feedproxy.google.com/~r/seanhess/~3/rglU-VmgrS8/sinatra_blog_tutorial_part_2</link>
	<!--<comments>http://codearchive.seanhess.net/?p=225#comments</comments>-->
	<pubDate>Fri, 31 Jul 2009 00:00:00 EDT</pubDate><!-- Fri, 19 Jun 2009 07:27:52 +0000 -->
	<dc:creator>sean</dc:creator>
	
	
		<category><![CDATA[Sequel]]></category>
	
		<category><![CDATA[Sinatra]]></category>
	
		<category><![CDATA[Ruby]]></category>
	
		<category><![CDATA[Tutorial]]></category>
	
	
	<guid isPermaLink="false">http://seanhess.net/posts/sinatra_blog_tutorial_part_2</guid>
	<description><![CDATA[ This is part 2 of my Sinatra blog tutorial. Today I&#8217;m talking about the database layer. Don&#8217;t forget to check out the full source of my blog on github.      Source on Github     I used  sequel  as the ORM for this blog. I had originally wanted to use DataMapper, but I ran into some probl]]></description>
	<content:encoded><![CDATA[<p>This is part 2 of my Sinatra blog tutorial. Today I&#8217;m talking about the database layer. Don&#8217;t forget to check out the full source of my blog on github.</p>

<p class='download'> <a href='http://github.com/seanhess/Blog'>Source on Github</a></p>

<p>I used <a href='http://sequel.rubyforge.org/documentation.html' title='Sequel'>sequel</a> as the ORM for this blog. I had originally wanted to use DataMapper, but I ran into some problems. They&#8217;re pretty similar anyway.</p>

<p>First, we need to give the connection information to Sequel. I put my database info in a yaml file because I wanted to be able to pass the command-line migration tool the same info. I require this file from my &#8220;controller&#8221;. It&#8217;s important to remember that the following files aren&#8217;t a sinatra standard or anything. You can organize your files however you like.</p>

<p>data/init.rb</p>

<pre><code>require &#39;rubygems&#39;
require &#39;sequel&#39;
require &#39;yaml&#39;

content = File.new(&quot;data/database.yml&quot;).read
settings = YAML::load content
DB = Sequel.connect &quot;#{settings[&#39;adapter&#39;]}://#{settings[&#39;username&#39;]}:#{settings[&#39;password&#39;]}@#{settings[&#39;host&#39;]}/#{settings[&#39;database&#39;]}&quot;

require &#39;data/models&#39;</code></pre>

<p>data/database.yml</p>

<pre><code>adapter: mysql
host: localhost
username: root
password: root
database: custom_blog</code></pre>

<p>Here are my models. The syntax of these models will look similar to active record. There aren&#8217;t much to them. A few things to notice are that I used simple many_to_many and one_to_many associations.</p>

<p>data/models.rb</p>

<pre><code>require &#39;rubygems&#39;
require &#39;sequel&#39;

class Post &lt; Sequel::Model
  Page = &quot;page&quot;
  Post = &quot;post&quot;

  many_to_many :tags
  one_to_many :comments

  def date
    created.strftime &quot;%B %d, %Y&quot;
  end

  def summary(length=300)
    body.gsub(/(&lt;[^&gt;]*&gt;)|\n|\t/s,&quot; &quot;)[0..length]
  end

  def update_title(value)

    raise &quot;[ ! ] Could not find title for post&quot; if value.nil?

    self.title = value
    self.name = value.downcase.gsub(/[^\w]/,&quot;_&quot;).gsub(/__/,&quot;&quot;)
  end
end

class Tag &lt; Sequel::Model
  many_to_many :posts, :order =&gt; :created.desc
end

class Comment &lt; Sequel::Model
  many_to_one :posts

  def post
    Post[:id =&gt; post_id]
  end
end</code></pre>

<p>These behave as expected. The syntax is only slightly different from active record. Sequel allows you to chain commands to a dataset together, which makes it easy to create complex queries.</p>

<pre><code>Post.all
Post.first.comments
Post.filter(:kind =&gt; Post::Page).reverse_order(:created).all
Post.first.tags</code></pre>

<p>I&#8217;ll give you more concrete examples when we cover the controller. The next thing to look at is the migration. Now, I don&#8217;t really like migrations, but until these ORMs add support to dynamically update the database schema, I&#8217;m stuck with them. Here&#8217;s where I&#8217;m at currently.</p>

<p>data/001_BaseSchema.rb</p>

<pre><code>require &#39;data/models&#39;

class BaseSchema &lt; Sequel::Migration
  def up
    create_table! :posts do
      primary_key :id
      String :title
      Text :body
      Time :mtime
      Time :created
      String :kind, :default =&gt; Post::Post
      String :file
      String :name
    end

    create_table! :tags do 
      primary_key :id
      String :name
    end

    create_table! :posts_tags do
      primary_key :id
      foreign_key :tag_id, :tags
      foreign_key :post_id, :posts
    end      
  end

  def down
    drop_table :posts
    drop_table :tags
    drop_table :posts_tags
  end
end</code></pre>

<p>data/002_Comments.rb</p>

<pre><code>require &#39;data/models&#39;

class Comments &lt; Sequel::Migration
  def up
    create_table! :comments do
      primary_key :id
      foreign_key :post_id, :posts

      String :name
      String :email
      String :url
      Text :body
    end
  end

  def down
    drop_table :comments
  end
end</code></pre>

<p>To run the migrations, you use the sequel command-line tool. Here, I&#8217;m telling it to run migrations from my <code>data</code> folder, and to use <code>data/database.yml</code> for connection info.</p>

<pre><code>sequel -m data data/database.yml
sequel -m data data/database.yml -M 1 # migrates to 001</code></pre>

<p>That&#8217;s it for now!</p><img src="http://feeds.feedburner.com/~r/seanhess/~4/rglU-VmgrS8" height="1" width="1"/>]]></content:encoded>
	<!--<wfw:commentRss>http://codearchive.seanhess.net/?feed=rss2&amp;p=225</wfw:commentRss>-->
<feedburner:origLink>http://seanhess.net/posts/sinatra_blog_tutorial_part_2</feedburner:origLink></item>

<item>
	<title>Page Stack - Navigate by Page Name</title>
	<link>http://feedproxy.google.com/~r/seanhess/~3/MjtJz7RXgsE/page_stack</link>
	<!--<comments>http://codearchive.seanhess.net/?p=225#comments</comments>-->
	<pubDate>Thu, 30 Jul 2009 00:00:00 EDT</pubDate><!-- Fri, 19 Jun 2009 07:27:52 +0000 -->
	<dc:creator>sean</dc:creator>
	
	
		<category><![CDATA[Component]]></category>
	
		<category><![CDATA[Flex]]></category>
	
	
	<guid isPermaLink="false">http://seanhess.net/posts/page_stack</guid>
	<description><![CDATA[ Building a navigation system in Flex is harder than it should be. Trying to figure out how to decouple your navigation model from the view is unintuitive.  ViewStack  is the obvious choice for it, but it leaves you with only two options, neither of which is good.         Use  selectedIndex   - You c]]></description>
	<content:encoded><![CDATA[<p>Building a navigation system in Flex is harder than it should be. Trying to figure out how to decouple your navigation model from the view is unintuitive. <code>ViewStack</code> is the obvious choice for it, but it leaves you with only two options, neither of which is good.</p>

<ol>
<li>
<p><em>Use <code>selectedIndex</code></em> - You can throw your pages/containers in a <code>ViewStack</code> and store the currently selected page index in a model. This works great, except that your model is coupled to the order of the pages in the <code>ViewStack</code>. You can store the indices in constants, but if someone adds a new page in there, it will throw off all the indices.</p>
</li>

<li>
<p><em>Use <code>selectedChild</code></em> - You can mitigate the index problem by storing the <code>selectedChild</code> property on your model, but then your model has a reference to a view. Yuck.</p>
</li>
</ol>

<h2 id='the_solution__page_stack'>The solution - Page Stack</h2>

<p>This simple component allows you to store the <code>name</code> of the selected page. You can set the page. You can then store a string on your model that you bind to the <code>selectedPage</code> property of <code>PageStack</code>. If you set the <code>name</code> on each child of the <code>PageStack</code>, they&#8217;ll match up.</p>

<p>MyView.mxml</p>

<pre><code>&lt;components:PageStack selectedPage=&quot;{navigation.selectedPage}&quot;&gt;
    &lt;mx:Canvas name=&quot;{Navigation.FIRST}&quot;/&gt;
    &lt;mx:Canvas name=&quot;{Navigation.SECOND}&quot;/&gt;
    &lt;mx:Canvas name=&quot;{Navigation.THIRD}&quot;/&gt;                
&lt;/components:PageStack&gt;

&lt;mx:Button label=&quot;Go to Page 3&quot; click=&quot;navigation.selectedPage = Navigation.THIRD&quot;/&gt;</code></pre>

<p>Navigation.as</p>

<pre><code>public class Navigation
{
    public static const FIRST:String = &quot;first&quot;;
    public static const SECOND:String = &quot;second&quot;;
    public static const THIRD:String = &quot;third&quot;;
        
    [Bindable]            
    public var selectedPage:String = FIRST;
}</code></pre>

<p>And here&#8217;s the source!</p>

<pre><code>package net.seanhess.components
{
    import flash.display.DisplayObject;

    import mx.containers.ViewStack;
    import mx.core.Container;

    public class PageStack extends ViewStack
    {
        protected var pages:Object = {};
        protected var newChildren:Boolean = false;

        override public function addChildAt(child:DisplayObject, index:int) : DisplayObject
        {
            newChildren = true;
            invalidateProperties();
            return super.addChildAt(child, index);
        }

        override protected function commitProperties() : void
        {
            super.commitProperties();

            if (newChildren)
            {
                newChildren = false;
                pages = {};

                for each (var child:DisplayObject in getChildren())
                {
                    var name:String = child.name;
                    pages[name] = child;
                }
            }
        }

        public function set selectedPage(value:String):void
        {
            var child:Container = pages[value] as Container;

            if (!child)
                throw new Error(&quot;Could not find page: &quot; + value);

            selectedChild = child;
        }

        public function get selectedPage():String
        {
            return selectedChild.name;            
        }
    }
}</code></pre><img src="http://feeds.feedburner.com/~r/seanhess/~4/MjtJz7RXgsE" height="1" width="1"/>]]></content:encoded>
	<!--<wfw:commentRss>http://codearchive.seanhess.net/?feed=rss2&amp;p=225</wfw:commentRss>-->
<feedburner:origLink>http://seanhess.net/posts/page_stack</feedburner:origLink></item>

<item>
	<title>Custom Block Helper in ERB</title>
	<link>http://feedproxy.google.com/~r/seanhess/~3/yEGf9FN6yZo/erb_form_block</link>
	<!--<comments>http://codearchive.seanhess.net/?p=225#comments</comments>-->
	<pubDate>Wed, 29 Jul 2009 00:00:00 EDT</pubDate><!-- Fri, 19 Jun 2009 07:27:52 +0000 -->
	<dc:creator>sean</dc:creator>
	
	
		<category><![CDATA[Ruby]]></category>
	
	
	<guid isPermaLink="false">http://seanhess.net/posts/erb_form_block</guid>
	<description><![CDATA[ Something I learned how to do in rails, but had a hard time replicating without it, is create a custom helper that accepts a block. I figured out how to write to the screen from the helper.  @_out_buf  is the name of the variable I needed.     # myview.erb &lt;% form(&quot;/login&quot;, :post) do %&]]></description>
	<content:encoded><![CDATA[<p>Something I learned how to do in rails, but had a hard time replicating without it, is create a custom helper that accepts a block. I figured out how to write to the screen from the helper. <code>@_out_buf</code> is the name of the variable I needed.</p>

<pre><code># myview.erb
&lt;% form(&quot;/login&quot;, :post) do %&gt;
	&lt;p&gt;Username: &lt;input type=&quot;text&quot; name=&quot;username&quot;&gt;&lt;/p&gt;
	&lt;p&gt;Password: &lt;input type=&quot;password&quot; name=&quot;password&quot;&gt;&lt;/p&gt;
&lt;% end %&gt;

# helpers.rb
def form(url, method, &amp;block)
  @_out_buf &lt;&lt; &quot;&lt;form action=&#39;#{url}&#39; method=&#39;post&#39;&gt;&quot;
  @_out_buf &lt;&lt; &quot;&lt;input type=&#39;hidden&#39; name=&#39;_method&#39; value=&#39;#{method}&#39;&gt;&quot;
  yield
  @_out_buf &lt;&lt; &quot;&lt;/form&gt;&quot;
end</code></pre><img src="http://feeds.feedburner.com/~r/seanhess/~4/yEGf9FN6yZo" height="1" width="1"/>]]></content:encoded>
	<!--<wfw:commentRss>http://codearchive.seanhess.net/?feed=rss2&amp;p=225</wfw:commentRss>-->
<feedburner:origLink>http://seanhess.net/posts/erb_form_block</feedburner:origLink></item>

<item>
	<title>A New Home</title>
	<link>http://feedproxy.google.com/~r/seanhess/~3/DusmMZ9tA74/new_blog</link>
	<!--<comments>http://codearchive.seanhess.net/?p=225#comments</comments>-->
	<pubDate>Tue, 28 Jul 2009 00:00:00 EDT</pubDate><!-- Fri, 19 Jun 2009 07:27:52 +0000 -->
	<dc:creator>sean</dc:creator>
	
	
		<category><![CDATA[Design]]></category>
	
		<category><![CDATA[Site]]></category>
	
		<category><![CDATA[Ruby]]></category>
	
	
	<guid isPermaLink="false">http://seanhess.net/posts/new_blog</guid>
	<description><![CDATA[ My blog has been going through a state of flux lately. I hadn&#8217;t posted in a couple of months, and when I discovered  posterous , I thought I had found the perfect system. Well, it didn&#8217;t make me post any more than I used to - it just made my blog look worse.    A few weeks ago I sat down]]></description>
	<content:encoded><![CDATA[<p>My blog has been going through a state of flux lately. I hadn&#8217;t posted in a couple of months, and when I discovered <a href='http://posterous.com'>posterous</a>, I thought I had found the perfect system. Well, it didn&#8217;t make me post any more than I used to - it just made my blog look worse.</p>

<p>A few weeks ago I sat down with <a href='http://mjijackson.com' title='Michael Jackson'>Michael Jackson</a> (no, not that one). He showed off his new blog, written from scratch in one week, and I was instantly jealous. I&#8217;ve been using wordpress for more than a year, and although it&#8217;s a good system, I was always intimidated out of customizing it.</p>

<p>Well, a few weeks later (it took me longer), and hundreds of dollars of time poorer, here it is.</p>

<p class='download'> <a href='http://github.com/seanhess/Blog.git'>Download the code on github</a></p>

<h2 id='how_does_it_work'>How does it work?</h2>

<p>I&#8217;ve been dabbling with ruby for a year now, but haven&#8217;t had the chance to put anything into production. The site was created using <a href='http://www.sinatrarb.com'>Sinatra</a> - an incredibly slick, performant ruby DSL. I used erb as the templating language, and <a href='http://sequel.rubyforge.org/'>Sequel</a> as my ORM.</p>

<p>One of the coolest things about it, which I totally ripped off of <a href='http://mjijackson.com' title='Michael Jackson'>Michael</a>, is that all the posts are written as flat markdown files, rsynched to the server. Metadata for the posts is at the top of the file, and the files are converted to html only if they&#8217;ve changed. All it takes is one <code>cap deploy</code>. Here&#8217;s an example of what a post looks like</p>

<pre><code>Title: A New Home
Tags: Ruby, Code, Site

My blog has been going through a state of flux lately. I hadn&#39;t posted in a couple
of months, and when I discovered [posterous](http://posterous.com), I thought...</code></pre>

<h2 id='ruby_ftw'>Ruby FTW</h2>

<p>Back a few months ago, I was just starting to get sick of trying to learn rails. It had been nearly a year since I started, and I still didn&#8217;t get it. To top it off, I had been forced to use php for another project at work, and it felt so refreshing I swore I&#8217;d never go back.</p>

<p>I started to realize that there are other ruby frameworks out there, including Merb, Ramaze, and Sinatra (discovered in that order). Leaving rails behind was the best thing I ever did. I learned ruby. Ruby is awesome.</p>

<h2 id='design'>Design</h2>

<p>I also designed the thing from scratch. The design was definitely inspired by many on <a href='http://www.thebestdesigns.com/'>The Best Designs</a>. I used <a href='http://blueprintcss.org'>Blueprint</a>, which made the css way easier. I took some icons from <a href='http://dryicons.com'>Dry Icons</a> and the background image from <a href='http://echoenduring.com'>Echo Enduring</a>.</p><img src="http://feeds.feedburner.com/~r/seanhess/~4/DusmMZ9tA74" height="1" width="1"/>]]></content:encoded>
	<!--<wfw:commentRss>http://codearchive.seanhess.net/?feed=rss2&amp;p=225</wfw:commentRss>-->
<feedburner:origLink>http://seanhess.net/posts/new_blog</feedburner:origLink></item>

	
</channel>
</rss>
