Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
New template
  • Loading branch information
hoverbird committed Jul 16, 2011
1 parent 2b3b836 commit 6d627dd
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 16 deletions.
4 changes: 2 additions & 2 deletions Gemfile
Expand Up @@ -4,10 +4,10 @@ group :default do
gem "chance"
gem "thin"
gem "sinatra"
# gem "active_support"
gem "active_support"
gem "shotgun"
end

group :spec do
gem 'rspec'
gem "rspec"
end
3 changes: 2 additions & 1 deletion README.markdown
Expand Up @@ -20,4 +20,5 @@ I tried to set this up so it should be as easy to extend as possible. To this e

- templates: Simple ERB (embedded Ruby) templates that Storying will pick randomly and render. Add new templates here and they'll be thrown in the mix.

- lib: The lib directory is where the stories are constructed. Here you'll find the Story class itself, which randomly selects its basic components when constructed with `Story.new`. The story will automatically have a setting, a hero, a supporting_character etc. Investigate these other types to get an idea of the components so far. Adding to these basic types will be slightly trickier than just dropping in new story elements and templates, but just barely.
- lib/storying: The lib directory is where the stories are constructed. Here you'll find the Story class itself, which randomly selects its basic components when constructed with `Story.new`. The story will automatically have a setting, a hero, a supporting_character etc. Investigate these other types to get an idea of the components so far. Adding to these basic types will be slightly trickier than just dropping in new story elements and templates, but just barely. Fire up a new *.rb file and the class you define there will be available in your stories. Add a has_randomized_story_element declaration and each new instance of the class will have that attribute, plucked from the story_elements. Or define your own attributes. Go nuts.

1 change: 1 addition & 0 deletions lib/storying/story.rb
Expand Up @@ -2,6 +2,7 @@ module Storying
class Story
include StoryElements
has_randomized_story_element :setting, :conflict

attr_reader :hero
attr_accessor :supporting_character, :villain

Expand Down
13 changes: 8 additions & 5 deletions lib/storying/story_elements.rb
@@ -1,7 +1,8 @@
module Storying
module StoryElements
STORY_ELEMENTS_PATH = ROOT + "/story_elements"
include ActiveSupport::Inflector

STORY_ELEMENTS_PATH = ROOT + "/story_elements"
class << self
def included(base)
base.extend(ClassMethods)
Expand All @@ -20,21 +21,23 @@ module ClassMethods

# Creates an accessor returning a randomly selected Story element from the Storying module.
# i.e. `has_randomized_story_element :name` creates methods equivalent to the following:
# def name
# @name ||= Storying.names.random
# end
#
# def name
# @name ||= Storying.names.random
# end
def has_randomized_story_element(*properties)
properties.each do |property|
define_method property.to_sym do
unless value = instance_variable_get("@#{property}".to_sym)
# FIXME poor man's pluralization
value = Storying.send("#{property}s").random
value = Storying.send(singularize(property.to_s)).random
instance_variable_set("@#{property}", value)
end
value
end
end
end
end

end
end
Empty file removed spec/character_attributes_spec.rb
Empty file.
16 changes: 16 additions & 0 deletions spec/story_spec.rb
@@ -0,0 +1,16 @@
require 'spec_helper'

describe Storying::Story do
attr_reader :story

context "when new" do
before do
@story = Storying::Story.new
end

it "has a hero and supporting character" do
@story.hero.should be_kind_of Storying::Hero
@story.supporting_character.should be_kind_of Storying::SupportingCharacter
end
end
end
7 changes: 7 additions & 0 deletions story_elements/nationalities.yml
@@ -0,0 +1,7 @@
---
- Italian
- Irish
- Nigerian
- Dutch
- Scottish
- Polish
1 change: 1 addition & 0 deletions story_elements/relationships_to_character.yml
Expand Up @@ -2,3 +2,4 @@
- loyal companion
- rival
- best friend
- mentor
2 changes: 2 additions & 0 deletions story_elements/settings.yml
Expand Up @@ -4,3 +4,5 @@
- an abandoned mining village in China
- a luxury villa in the shadow of a dormant volcano
- a skyscraper in midtown Manhattan
- an experimental architecture school
- a sleepy village on the Great Lakes
10 changes: 5 additions & 5 deletions storying.rb
Expand Up @@ -3,16 +3,15 @@
$:.unshift LIB_PATH

%w(story_elements gender character).each {|library| require library}
%w(rubygems bundler/setup chance yaml erb sinatra thin).each {|library| require library}
%w(rubygems bundler/setup chance yaml erb sinatra thin active_support/inflector).each {|library| require library}
Dir.entries(LIB_PATH).sort.each {|filename| require filename if filename =~ /\.rb$/ }

module Storying
include StoryElements

TEMPLATE_PATH = ROOT + "/templates"
TEMPLATES = Dir.glob(TEMPLATE_PATH + "/*.erb").map {|f| File.read f}

Dir.entries(LIB_PATH).sort.each do |filename|
require filename if filename =~ /\.rb$/
end
include StoryElements
get '/' do
random_template = TEMPLATES.random
begin
Expand All @@ -21,4 +20,5 @@ module Storying
raise "Error rendering #{random_template}:\n #{e}"
end
end

end
16 changes: 15 additions & 1 deletion templates/ireland.erb
@@ -1 +1,15 @@
In the winter of 1951, a storyteller arrives at the home of nine-year-old Ronan O'Mara in the Irish countryside. The last practitioner of an honored, centuries-old tradition, the Seanchai enthralls his assembled audience for three evenings running with narratives of foolish kings and fabled saints, of enduring accomplishments and selfless acts -- until he is banished from the household for blasphemy and moves on. But these three incomparable nights have changed young Ronan forever, setting him on the course he will follow for years to come -- as he persues the elusive, itinerant story teller ... and the magical tales that are no less than the glorious saga of his tenacious, troubled, and extraordinary isle.
<% story = Storying::Story.new %>

<p>
In the <%= %w(winter autumn summer spring).random %> of <%= (1950..1961).random %>, a <%= story.supporting_character.job %> arrives at the home of eight-year-old <%= story.hero.full_name %> in the <%= Storying.nationalities.random %> countryside. The last practitioner of an dying tradition, <%= story.supporting_character.full_name %> (as the <%= story.supporting_character.job %> is known) regales <%= story.hero.name %> with stories from <%= story.supporting_character.possessive_pronoun %> travels.
</p>
<p>
When <%= story.conflict %> strikes the village, <%= story.supporting_character %> falls under suspicion of local authorities. Young <%= story.hero %> is torn between <%= story.hero.possessive_pronoun %> new friend and <%= story.hero.possessive_pronoun %> elders. After <%= story.hero %>'s <%= Storying.relationships_to_character.random %> takes <%= story.supporting_character %>'s side, <%= story.hero %> tries to help <%= story.supporting_character.personal_pronoun(:object) %> escape.
</p>
<p>
<% if story.supporting_character.villain? %>
As a local <%= Storying.jobs.random %> begins looking into the case, <%= story.supporting_character.full_name %>'s story begins to unravel. A convoluted plot to win <%= story.supporting_character.goal %>
<% else %>
<%= story.hero %>'s unlikely friendship with the <%= story.supporting_character.job %> becomes a source of strength for years thereafter as <%= story.hero.personal_pronoun %> makes the journey into <%= story.hero.gender %>hood.
<% end %>
</p>
8 changes: 6 additions & 2 deletions templates/simple.erb
@@ -1,5 +1,9 @@
<% story = Storying::Story.new %>
<% hero = story.hero %>
<% support = story.supporting_character %>

A <%= hero.gender %> with a <%= hero.characteristic %>, <%= hero.name %> is an international operative who will stop at nothing to see justice done. Sometimes <%= hero.personal_pronoun %> must journey far in search of evil; sometimes evil finds <%= hero.personal_pronoun('object') %> in <%= story.setting %>. When a <%= story.conflict %> arises, only <%= hero.possessive_pronoun %> <%= support.relationship_to_hero %> <%= support.full_name %> can turn the tide. In a dangerous world, one extraordinary <%= support.gender %> can mean the difference between life and death...
<p>
A <%= hero.gender %> with a <%= hero.characteristic %>, <%= hero.name %> is an international operative who will stop at nothing to see justice done. Sometimes <%= hero.personal_pronoun %> must journey far in search of evil; sometimes evil finds <%= hero.personal_pronoun('object') %> in <%= story.setting %>.
</p>
<p>
When a <%= story.conflict %> arises, only <%= hero.possessive_pronoun %> <%= support.relationship_to_hero %> <%= support.full_name %> can turn the tide. In a dangerous world, one extraordinary <%= support.gender %> can mean the difference between life and death...
</p>

0 comments on commit 6d627dd

Please sign in to comment.