<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"><title>half-penny</title><link hreflang="en-US" href="http://half-penny.org/" rel="alternate" /><updated>2009-06-25T19:59:47-05:00</updated><id>http://half-penny.org/</id><generator uri="http://code.google.com/p/wistle">Wistle</generator><geo:lat>35.338716</geo:lat><geo:long>-97.535691</geo:long><link rel="self" href="http://feeds.feedburner.com/half-penny" type="application/atom+xml" /><entry><title>Wistle: Plans for 2009</title><updated>2009-05-30T15:10:00+00:00</updated><author><name>jmorgan</name></author><content type="xhtml" xml:lang="en-US"><div xmlns="http://www.w3.org/1999/xhtml" xmlns:fg="http://fromgenesis.org"><p>So, I’ve been pretty happy with Wistle, the <a href="http://www.merbivore.com">merb</a> app
that runs this blog and <a href="http://fromgenesis.org">fromgenesis.org</a>. But I’ve been
pondering the future of it. The design is somewhat monolothic, what with several
libraries and such just stuck in the lib directory. I’m now thinking about
focusing more on the app itself, rather than just the ability to store the
articles in Subversion, but the current setup is a bit too interconnected.
I would also like to easily re-use several of the bits in the lib directory in
other apps.</p>

<p>The driving force here is actually the comments. The views I have so far are
not real useful, and there’s no anti-spam measures whatsoever. And as I’ve
pondered what I want to do there–and now with some time away from the original
work–I’m thinking much more along “this is part of the app (the UI)” versus
“this is part of the back end”.</p>

<p>So, refactoring is at hand. I want to strike a useful balance between “trash it
and start over” and “make the changes that need to happen” (Although, since its
mostly a for-fun project, if I end up trashing a lot, no biggee). I’m
considering the best order to approach this; one in which I plan on doing the
comments updates last, but at which there are a number of points at which I
could stop and jump over to that. So, here goes.</p>

<h2>Move to git</h2>

<p><strong>Done 6/14/09 - <a href="http://github.com/jm81/wistle">http://github.com/jm81/wistle</a></strong></p>

<p>Wistle is currently SCM’ed in Subversion. I’d like to move it to git, and host
on github. No particular reason, other than for the chance for some more
learning. I’ve only done a little bit with git, and since it seems to be ‘the
thing’ among the merb/rails folks these days. The little I’ve used it, I’ve
liked it…</p>

<h2>Libraries to gems</h2>

<p>This is where the change really begins. I want to move libraries out to gems,
because there’s no reason for these things to be tied to the app. I foresee five
gems here:</p>

<ol>
<li><p><strong>Filters</strong></p>

<p>This is the library that allows for filtering text through, e.g. markdown,
textile, smartypants, etc. libraries. It will also contain a couple
built-in, which I could move out later. One of my favorite features of this
lib is the ease of choosing between a variety of implementations for a single
filter. For example, for markdown, I could use rdiscount or bluecloth,
depending on which is available.</p></li>
<li><p><strong>Pagination</strong></p>

<p><strong>(Mostly) Done 6/23/09 -
<a href="http://github.com/jm81/paginate">http://github.com/jm81/paginate</a></strong> -
See TODO file for future plans for this gem)</p>

<p>I know, there’s bazillions of pagination approaches out there. This gem would
just be for adding a method to DataMapper classes and collections:
<em>paginate</em>, which is just like <em>all</em>, but it receives a :page option (and
receives or assumes a :limit option). The result has two extra
methods: #pages is the number of pages given the current settings,
and #current_page is the number of the current page (1-indexed).</p>

<p>I should probably check what else is out there now, although I’ve
never completely liked other implementations I’ve seen, mostly because I
want to access the page number and total pages through a method on the
returned collection. If there’s something better out there, I probably
shouldn’t bother with the updates that are needed, such as adding
the #paginate method to DataMapper::Collection.</p>

<p>What I do have is somewhat based on
<a href="http://dm-is-paginated.rubyforge.org/">dm-is-paginated</a>.</p></li>
<li><p><strong>Pagination-slice</strong></p>

<p><strong>Update 6/25/09</strong> - I decided this was unneeded. The jm81-paginate gem
(above) now has a helper method (Paginate::Helpers::Merb#page_links) that
does what I had planned for this slice to do.</p>

<p>This involves figuring out merb slices, but that’s worth it. I have a helper
(might be part of the first library) and a view partial that I use quite a
bit, with slight variations. It’s based on someone else’s code, but I’m not
sure I remember what.</p>

<p>Anyway, I think I could create a useful slice, to make this code more easily
reusable. I’ll see.</p></li>
<li><p><strong>Subversion Fixtures</strong></p>

<p>Currently in lib/wistle/fixture.rb, this allows a fairly simple way to set up
a Subversion repository (which I use in testing the Subversion-to-Datamapper
stuff.<br />
</p></li>
<li><p><strong>Subversion-to-Datamapper</strong></p>

<p>The current lib/wistle directory, the stuff that extends a DataMapper class
to allow syncing from a Subversion repository.</p></li>
</ol>


<p>(A possible sixth gem has to do with “attachments”, along the lines of
attachment_fu. It’s not something currently required in Wistle, but I have one
more or less together that works more reasonably to me than other plugins
currently available)</p>

<h2>New Wistle lib approach</h2>

<p>Aside from the fact that the above needs to happen in order to simplify new
updates, what really interests me is this part. I want to break up the process
in the Subversion-to-Datamapper sync. In short, I want to place an intermediary,
which is the <a href="http://www.atomenabled.org/developers/protocol/">Atom Publishing
Protocol</a>. That way, I can use
Subversion to store and auto-publish to any blog app that accepts Atom
publishing. The blog app, then, can also accept from any client that publishes
via Atom. Both of these options are appealing to me, while still allowing the
Subversion to blog app as it currently is without any change from the
perspective of the article writer.</p>

<p>So, there would be two libraries/programs then, such as it is:</p>

<ul>
<li>Subversion to Atom</li>
<li>Atom parser to Ruby model</li>
</ul>


<p>Ideally, this could go in the opposite direction, so that, for example, I could
publish via Atom from Word and it would commit to the Subversion <em>and</em> update
the blog app. But I’ve not really investigated Atom to know if this would all be
easy enough to be worth it.</p>

<p>Another issue this will create is adding some sort of user privileges to
authenticate when users try to post articles, etc.</p>

<p>There will also probably need to be another library for updating the views and
public files from Subversion, and (possibly again elsewhere) the methods for
allowing the views and assets to be found in the right place in the file system
based on which site is currently active.</p>

<h2>Update app to new libs</h2>

<p>This would actually be an ongoing process, updating the blog app to move from
the existing integrated libraries to the new gems, including updating for any
modifications to those libraries (which will happen in at least some cases). But
at some point, I need to make a concerted effort to ensure this all has
happened. Which leads to…</p>

<h2>Clear separation of app and libs</h2>

<p>By this point, the blog app itself should be a distinct entity. It would accept
publishing adds, edits, etc. via Atom Publishing, and use the other libraries
as needed. But it would not be tied to Subversion as the storage mechanism, and
the gem could be used in other applications.</p>

<h2>Update versions of datamapper and merb</h2>

<p>Another thing that will need to happen, and I’m not sure <em>when</em>, is to update to
the latest and greatest datamapper and merb versions, and the latest svn-client
lib, which does have some changes. But those will need to happen at some point,
at this if not before.</p>

<h2>Fix comments</h2>

<p>Hey, now we get to really fix the comments, because there’s not all that other
stuff in the way. Obviously, this <em>could</em> happen sooner. It involves two major
pieces:</p>

<ol>
<li>Nicer looking default views.</li>
<li>Anti-spam. I’m currently looking at <a href="http://recaptcha.net/">reCAPTCHA</a>.
Another possibility I’ve considered is that the first time a visitor posts
a comment using a given email, they would receive a validation email. Since
I have no intention of actually showing commenters’ emails, this should be
workable.</li>
</ol>


<h2>General app cleanup</h2>

<p>Because, there will be stuff to clean up, right?</p>

<p>As a final comment, if anyone else is interested in working on this, please let
me know: jmorgan at morgancreative dot net. I don’t know that this project would
hold any interest for anyone else, but it would be silly of me not to ask, eh?</p>
</div></content><id>http://half-penny.org/wistle/2009-plans</id><link hreflang="en-US" href="http://half-penny.org/wistle/2009-plans" rel="alternate" /><category term="Wistle" /><published>2009-05-30T15:10:00+00:00</published></entry><entry><title>Thought for the Day</title><updated>2009-03-27T19:35:00+00:00</updated><author><name>jmorgan</name></author><content type="xhtml" xml:lang="en-US"><div xmlns="http://www.w3.org/1999/xhtml" xmlns:fg="http://fromgenesis.org"><p>An honest politician is like a regular roll of toilet paper. It’s a generally 
accepted measuring stick, but reports of actual sightings are rarely more than 
urban legends.</p>
</div></content><id>http://half-penny.org/politics/regular-roll</id><link hreflang="en-US" href="http://half-penny.org/politics/regular-roll" rel="alternate" /><category term="Politics" /><published>2009-03-27T19:35:00+00:00</published></entry><entry><title>Respect the Flag</title><updated>2009-01-03T17:21:14-06:00</updated><author><name>jmorgan</name></author><content type="xhtml" xml:lang="en-US"><div xmlns="http://www.w3.org/1999/xhtml" xmlns:fg="http://fromgenesis.org"><p>People who get uppity about the US flag. People who make cell phone calls
during movies. Cannibals. Sometimes it’s hard to decide which are the worst
examples of humanity.</p>

<p>Right, so this thing of people freaking out flag burning, the pledge of 
allegiance, or flag pins is really tiring. I suppose a rant about how Christians
are instructed not to worship idols would be off-topic (sorry, there’s a 
difference between physically following a banner, say, into battle, and
actually taking offense at someone not wearing a pin of that banner). Also, can
we acknowledge that very, very few people know the full lyrics to the 
Star-Spangled banner, and that the <a href="http://en.wikipedia.org/wiki/Pledge_of_allegiance">Pledge</a>
has only been around for about half the existence of this nation. So, for 
example, George Washington <em>did not</em> say it? Please?</p>

<p>But here’s how I think of the flag. It’s a symbol of our nation, particularly
of the unity of the states under the Constitution. Unity of purpose is what
the flag seems to most represent. At least to me. And yes, it’s a reminder of
those who have died fighting for this nation, both those who fought for good
causes, and sadly but importantly, those who gave their lives for ill-conceived
wars engaged to meet the goals of a few politicians.</p>

<p>So, politicians using the flag as part of their campaign is pretty 
contradictory. Let’s face it, most campaigns focus a lot on divisions, 
highlighting them even when they’re inconsequential and increasing those 
divisions. Is a politician where a flag pin really respecting that flag or what
it represents? I don’t think so.</p>

<p>In fact, for the flag obsessive that are always wanting to propose some
admendment to respect that flag, here’s what I propose: “No person may use the
US flag, images of it, or references to it, during the course of any campaign
for elected government office.” Because these games of (and admittedly it’s
often not the politicians themselves engaging in them) “I’m more patriotic than
you because I wear the flag pin, or say the pledge, or whatever,” aren’t
promoting unity, or indeed any of the many things that are great about the US.
No, those dirty and silly games are among the greatest disrespect than be shown
to that banner, or to the nation which it represents.</p>
</div></content><id>http://half-penny.org/politics/respect-the-flag</id><link hreflang="en-US" href="http://half-penny.org/politics/respect-the-flag" rel="alternate" /><category term="Politics" /><published>2009-03-13T12:00:00+00:00</published></entry><entry><title>Roles and Permissions on GraffitiWok</title><updated>2009-01-03T17:00:54-06:00</updated><author><name>jmorgan</name></author><content type="xhtml" xml:lang="en-US"><div xmlns="http://www.w3.org/1999/xhtml" xmlns:fg="http://fromgenesis.org"><p>So, I didn’t user merb-auth for GraffitiWok, partly because it wasn’t when I
started. But, actually, the users and roles was one of the more complicated
and app-specific parts to GraffitiWok, so I probably would have gone the full
custom route anyway.</p>

<p>The particularly interesting part (to me) where Board and Note specific 
permissions, based on two criteria: ownership of the object (an owner can do
anything to that object or to its Notes if the object is a Board) and general
permissions for all logged-in or guest users. Actually, the models are built
to allow per-user permissions, but its not really implemented.</p>

<p>So, there are actually six relevant models, which I’ll review briefly:</p>

<ol>
<li>User - The basic model for users</li>
<li>GuestUser - A singleton class representing an anonymous user. I’ll actually
ignore this in the subsequent discussion</li>
<li>Role - A role, which just records a name and id. For example, “editor” or
“poster”</li>
<li>UserRole - An intermediate model connecting a Role, a User, and a Board. That
is, it says “Bob (User) is an ‘editor’ (Role) on Board #1”</li>
<li>Permission - A name and id identifying a permission</li>
<li>RolePermission - An intermediate model connecting a Role with its many
permissions.</li>
</ol>


<p>So, a User has one or more Roles for a given Board (or, uses the default roles)
each of which then have a set of permissions, thus, per board, a User has a
given set of permissions. The upshot of this is some meta-programming to have
code like User.first(:email =&gt; ‘bob@example.com’).can_edit?(Note.get(1)). I like
it, anyway.</p>

<p>Here’s the interesting code:</p>

<pre><code>def process_permission(permission, obj)
  if obj.kind_of?(Note)
    board = obj.board
    permission += &amp;#8216;_note&amp;#8217;
  else
    board = obj
  end

  if p = Permission.first(:name =&gt; permission)
    return true if (obj.owner == self &amp;&amp; permission != &amp;#8216;create_note&amp;#8217;)
    return true if (permission == &amp;#8216;create_note&amp;#8217; &amp;&amp; obj.board &amp;&amp; obj.board.owner == self)
    ur = UserRole.all(:board_id =&gt; board.id, :user_id =&gt; self.id)
    ur = UserRole.all(:board_id =&gt; board.id, :user_id =&gt; -1) if ur.empty?
    return ur.collect{ |r| r.role.permissions}.flatten.include?(p)
  end

  return false
end

def method_missing(sym, *args)
  if sym.to_s =~ /\Acan_([\w_]+)\?\Z/
    return process_permission($1, args.first)
  end
  super
end

def respond_to?(sym, *args)
  # repond_to can_{permission}? methods if there is a permission with the
  # given name.
  return true if super

  if sym.to_s =~ /\Acan_([\w_]+)\?\Z/
    return (Permission.first(:name =&gt; $1) || 
      Permission.first(:name =&gt; $1 + &amp;#8220;_note&amp;#8221;) ?
      true : false)
  end

  return false
end
</code></pre>

<p>The process_permission method is where the real work goes on. If the object is
a Note, it actually checks for a permission with the suffix _note on the given
Board (with some special coding for can_create_note?). It also uses the default
Roles (those for the Board where the User id is -1) if that User has no assigned
roles for this Board (a similar thing happens with GuestUser).</p>

<p>For GraffitiWok, I think this approach has worked rather well.</p>
</div></content><id>http://half-penny.org/graffitiwok/roles</id><link hreflang="en-US" href="http://half-penny.org/graffitiwok/roles" rel="alternate" /><category term="GraffitiWok.com" /><published>2009-03-06T17:15:00+00:00</published></entry><entry><title>Using Git</title><updated>2009-01-03T16:02:03-06:00</updated><author><name>jmorgan</name></author><content type="xhtml" xml:lang="en-US"><div xmlns="http://www.w3.org/1999/xhtml" xmlns:fg="http://fromgenesis.org"><p>So, I decided to try out <a href="http://en.wikipedia.org/wiki/Git_%28software">git</a>)
while developing <a href="http://graffitiwok.com">GraffitiWok</a> instead of Subversion
which I normally use for version control. I’ve been quite please with
Subversion and have found uses for it beyond just versioning software
development (see <a href="/wistle">Wistle</a>), but I’d started hearing a lot about git
at about the same point I started working on GraffitiWok.</p>

<p>First and foremost, the people who still claim you can’t use git on Windows
are apparently nuts. I have been doing so for nearly a year using <a href="http://code.google.com/p/msysgit/downloads/list">this
download</a>. So, what have been
my impressions.</p>

<p>I love the ability to easily add only a part of the changes in a file to a
commit. I realize that running into the need to do this reveals an occassional
lack of planning on my part, but it’s really nice. I also really like the
ability to amend the last commit. This has come in handy several times as well.</p>

<p>What I haven’t really tried is the branching and merging. Most of the projects
I’ve used version control for have been my own; I’ve never programmed on a team.
Still, even without that, git is at least as good as Subversion. Or, that is to
say, on a one person team, I’m not sure there’s a particular difference.</p>
</div></content><id>http://half-penny.org/graffitiwok/git</id><link hreflang="en-US" href="http://half-penny.org/graffitiwok/git" rel="alternate" /><category term="GraffitiWok.com" /><published>2009-03-06T01:45:00+00:00</published></entry></feed>
