jeremylightsmith-actionsite 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/Rakefile +23 -0
  2. data/example/src/helpers/blues_hero_helper.rb +28 -0
  3. data/example/src/images/batjeremy.jpg +0 -0
  4. data/example/src/images/black_header.png +0 -0
  5. data/example/src/images/black_header_with_slogan.png +0 -0
  6. data/example/src/images/chris.jpg +0 -0
  7. data/example/src/images/hawk-karissa.png +0 -0
  8. data/example/src/images/header.png +0 -0
  9. data/example/src/images/jeremy.jpg +0 -0
  10. data/example/src/images/jocelyn.jpg +0 -0
  11. data/example/src/images/karen.jpg +0 -0
  12. data/example/src/images/karissa.jpg +0 -0
  13. data/example/src/images/kevin.jpg +0 -0
  14. data/example/src/images/lessa.jpg +0 -0
  15. data/example/src/images/lucy.jpg +0 -0
  16. data/example/src/images/menu_bar.png +0 -0
  17. data/example/src/images/simple_header.png +0 -0
  18. data/example/src/images/solomon.jpg +0 -0
  19. data/example/src/images/supertopher.jpg +0 -0
  20. data/example/src/images/supertopher_and_batjeremy.jpg +0 -0
  21. data/example/src/images/teacher_contact_sheet.jpg +0 -0
  22. data/example/src/images/topher.jpg +0 -0
  23. data/example/src/index.html.erb +15 -0
  24. data/example/src/layouts/application.html.erb +47 -0
  25. data/example/src/register.html.erb +6 -0
  26. data/example/src/schedule.html.erb +34 -0
  27. data/example/src/stylesheets/application.css +131 -0
  28. data/example/src/teachers.html.erb +54 -0
  29. data/lib/action_site.rb +17 -0
  30. data/lib/action_site/context.rb +18 -0
  31. data/lib/action_site/extensions/string.rb +13 -0
  32. data/lib/action_site/generators/erb_generator.rb +9 -0
  33. data/lib/action_site/generators/markaby_generator.rb +11 -0
  34. data/lib/action_site/generators/redcloth_generator.rb +10 -0
  35. data/lib/action_site/generators/yaml_generator.rb +9 -0
  36. data/lib/action_site/helpers/form_helper.rb +6 -0
  37. data/lib/action_site/helpers/markaby_helper.rb +9 -0
  38. data/lib/action_site/helpers/url_helper.rb +26 -0
  39. data/lib/action_site/html_generator.rb +41 -0
  40. data/lib/action_site/page_context.rb +68 -0
  41. data/lib/action_site/site.rb +77 -0
  42. data/readme.txt +0 -0
  43. data/spec/action_site/context_spec.rb +16 -0
  44. data/spec/action_site/extensions/string_spec.rb +16 -0
  45. data/spec/action_site/helpers/form_helper_spec.rb +7 -0
  46. data/spec/action_site/helpers/url_helper_spec.rb +45 -0
  47. data/spec/action_site/html_generator_spec.rb +114 -0
  48. data/spec/action_site/page_context_spec.rb +32 -0
  49. data/spec/spec_helper.rb +8 -0
  50. metadata +137 -0
@@ -0,0 +1,23 @@
1
+ $LOAD_PATH << File.expand_path(File.dirname(__FILE__) + "/lib")
2
+
3
+ require 'action_site'
4
+ require 'spec/rake/spectask'
5
+
6
+ task :default => [:spec, :example]
7
+
8
+ Spec::Rake::SpecTask.new(:spec) do |t|
9
+ t.spec_files = FileList['spec/**/*_spec.rb']
10
+ end
11
+
12
+ desc "generate the example site"
13
+ task :example do
14
+ ActionSite::Site.new("example/src", "example/public").generate
15
+ end
16
+
17
+ desc "generate gemspec"
18
+ task :gemspec do
19
+ File.open("actionsite.gemspec", "w") do |f|
20
+ f << ERB.new(File.read("actionsite.gemspec.erb"), 0, "%<>").result(binding)
21
+ end
22
+ end
23
+
@@ -0,0 +1,28 @@
1
+ module BluesHeroHelper
2
+ def teacher(sym, name, super_powers = "", bio = "")
3
+ %{
4
+ <div class="teacher">
5
+ <a name="#{sym}"/>
6
+ #{image_tag "#{sym}.jpg"}
7
+
8
+ <table border="2" cellspacing="0">
9
+ <tr>
10
+ <th>Name:</th>
11
+ <td>#{name}</td>
12
+ </tr>
13
+ <tr>
14
+ <th>Superpowers:</th>
15
+ <td>#{super_powers}</td>
16
+ </tr>
17
+ <tr>
18
+ <th>History:</th>
19
+ <td>#{bio}</td>
20
+ </tr>
21
+ </table>
22
+
23
+ <div style="clear: both;"></div>
24
+ </div>
25
+ }
26
+ end
27
+
28
+ end
@@ -0,0 +1,15 @@
1
+ % content_for(:current_tab) { "home" }
2
+ % content_for(:superhero) { "supertopher.jpg" }
3
+
4
+ <div class="home_info">
5
+ <b>Blues Hero Workshop is coming to Seattle May 10th &amp; 11th!</b>
6
+ <br/>
7
+ <br/>
8
+ <div class="short_summary">
9
+ One room, ten instructors to choose from, and three hours to unlock your superblues power with an hour of specialized instruction and time to practice in between short privates.
10
+ </div>
11
+ <br/>
12
+ <br/>
13
+ <br/>
14
+ <a href="/register.html" id="register_button">REGISTER NOW!</a>
15
+ </div>
@@ -0,0 +1,47 @@
1
+ <html>
2
+ <head>
3
+ <title>Blues Hero Workshop</title>
4
+ <meta content="A different kind of Blues Dancing Workshop" name="description">
5
+ <meta content="seattle,blues,dance,lindy,dj,teaching" name="keywords">
6
+ <meta content="Jeremy Stell-Smith" name="author">
7
+ <link href="stylesheets/application.css" media="all" rel="stylesheet" type="text/css">
8
+ </head>
9
+ <body>
10
+ <div class="content <%= content_for_current_tab %>">
11
+ % if content_for_current_tab == "home"
12
+ <%= image_tag "black_header_with_slogan.png" %>
13
+ % else
14
+ <%= image_tag "black_header.png" %>
15
+ % end
16
+
17
+ <div class="navigation">
18
+ <%= link_to "home", "index.html", :class => "home_tab" %>
19
+ <%= link_to "register", "register.html", :class => "register_tab" %>
20
+ <%= link_to "teachers", "teachers.html", :class => "teachers_tab" %>
21
+ <%= link_to "schedule", "schedule.html", :class => "schedule_tab" %>
22
+ </div>
23
+
24
+ <div class="prepage">
25
+ <%= content_for_prepage if content_for_prepage? %>
26
+ </div>
27
+
28
+ <div class="page">
29
+ % if content_for_superhero?
30
+ <%= image_tag "#{content_for_superhero}", :style => "float: left; padding-top: 1em;" %>
31
+
32
+ <div class="right_panel">
33
+ <%= content %>
34
+ </div>
35
+ % else
36
+ <%= content %>
37
+ % end
38
+
39
+ <div style="clear: both;"></div>
40
+ </div>
41
+
42
+ <div class="credits">
43
+ this workshop brought to you by <%= link_to "Jeremy &amp; Karissa", "http://jeremyandkarissa.com/" %>
44
+ </div>
45
+ </div>
46
+ </body>
47
+ </html>
@@ -0,0 +1,6 @@
1
+ % content_for(:current_tab) { "register" }
2
+ % content_for(:superhero) { "hawk-karissa.png" }
3
+
4
+ <h1>REGISTER</h1>
5
+
6
+ <em>Sorry, registration closed a long time ago...</em>
@@ -0,0 +1,34 @@
1
+ % content_for(:current_tab) {"schedule"}
2
+ % content_for(:superhero) {"batjeremy.jpg"}
3
+
4
+ <div class="schedule">
5
+ <h1>SCHEDULE</h1>
6
+
7
+ <h2>WORKSHOP</h2>
8
+
9
+ Halo - 500 E Pike St, Seattle, WA -
10
+ <a href="http://maps.google.com/maps?f=q&hl=en&geocode=&q=500+E+Pike+St&sll=47.60356,-122.32944&sspn=0.225933,0.466919&ie=UTF8&ll=47.614684,-122.32549&spn=0.007059,0.014591&z=16&iwloc=addr&iwstate1=actions">map</a>
11
+
12
+ <table>
13
+ <tr>
14
+ <td>SAT</td>
15
+ <td>12p-3:15p</td>
16
+ </tr>
17
+ <tr>
18
+ <td>SUN</td>
19
+ <td>12p-3:15p</td>
20
+ </tr>
21
+ </table>
22
+
23
+ <h2>BLUES PARTY</h2>
24
+
25
+ <del>Our House</del> Fortress of Solitude - 10100 4th Ave NW, Seattle, WA -
26
+ <a href="http://maps.google.com/maps?f=q&hl=en&geocode=&q=10100+4th+Ave+NW,+Seattle+(home)&sll=47.708491,-122.359757&sspn=0.014092,0.029182&ie=UTF8&ll=47.70348,-122.361689&spn=0.007047,0.014591&z=16&iwloc=addr">map</a>
27
+
28
+ <table cellspacing="0">
29
+ <tr>
30
+ <td>SAT</td>
31
+ <td>10p-3:30a</td>
32
+ </tr>
33
+ </table>
34
+ </div>
@@ -0,0 +1,131 @@
1
+ html {
2
+ background-color: black;
3
+ }
4
+ body {
5
+ font-family: "Comic Sans MS", Arial;
6
+ /* color: #679de5;*/
7
+ margin: 0;
8
+ }
9
+
10
+ img { border: none;}
11
+
12
+ div.content {
13
+ width: 1024px;
14
+ margin-left:auto;
15
+ margin-right:auto;
16
+ }
17
+
18
+ .navigation {
19
+ float: right;
20
+ margin-top: -1.7em;
21
+ font-size: 120%;
22
+ padding: 0.2em 1em 0.2em;
23
+ color: black;
24
+ }
25
+
26
+ .navigation a {
27
+ text-decoration: none;
28
+ color: black;
29
+ background-color: #666;
30
+ padding: 0.1em 0.4em;
31
+ margin: 0 0.2em;
32
+ }
33
+
34
+ .home .navigation a.home_tab { background-color: white;}
35
+ .register .navigation a.register_tab { background-color: white;}
36
+ .teachers .navigation a.teachers_tab { background-color: white;}
37
+ .schedule .navigation a.schedule_tab { background-color: white;}
38
+
39
+ div.page {
40
+ padding: 0 1.5em 1.5em 1.5em;
41
+ background-color: white;
42
+ }
43
+
44
+ h1 {
45
+ margin-top: 0;
46
+ }
47
+
48
+ h2 {
49
+ border-bottom: 3px solid black
50
+ }
51
+
52
+ .home_info {
53
+ padding-top: 1em;
54
+ font-size: 140%;
55
+ }
56
+
57
+ .right_panel {
58
+ padding-left: 14em;
59
+ }
60
+
61
+ a#register_button {
62
+ color: white;
63
+ margin-left: 5em;
64
+ background-color: #d00;
65
+ padding: 0.3em 1em;
66
+ border: solid 4px;
67
+ border-top-color: #f44;
68
+ border-right-color: #900;
69
+ border-bottom-color: #800;
70
+ border-left-color: #f44;
71
+ }
72
+
73
+ #contact_sheet {
74
+ margin-left: -1.5em;
75
+ }
76
+
77
+ .credits {
78
+ padding: 1em;
79
+ text-align: right;
80
+ }
81
+
82
+ .credits, .credits a { color: #666; }
83
+
84
+ .schedule table {
85
+ border: solid 1px;
86
+ border-right: none;
87
+ }
88
+
89
+ .schedule table td {
90
+ border-right: solid 1px;
91
+ padding: 0.3em;
92
+ }
93
+
94
+ .teachers .teacher {
95
+ padding-bottom: 1em;
96
+ }
97
+
98
+ .teachers .teacher img {
99
+ float: left;
100
+ }
101
+
102
+ .teachers .teacher table {
103
+ margin-left: 1em;
104
+ }
105
+
106
+ .teachers .teacher th {
107
+ vertical-align: top;
108
+ text-align: right;
109
+ }
110
+
111
+ .teachers .teacher th,
112
+ .teachers .teacher td {
113
+ padding: 0.3em;
114
+ }
115
+
116
+ .fieldWithErrors {
117
+ display: inline;
118
+ }
119
+
120
+ .fieldWithErrors * {
121
+ background-color: f99;
122
+ }
123
+
124
+ .formError {
125
+ color: red;
126
+ font-weight: bold;
127
+ }
128
+
129
+ label b {
130
+ color: red;
131
+ }
@@ -0,0 +1,54 @@
1
+ % helper :blues_hero
2
+ % content_for(:current_tab) { "teachers" }
3
+
4
+ <h1>TEACHERS</h1>
5
+
6
+ <%= image_tag "teacher_contact_sheet.jpg", :size => "1024x483", :usemap => "#teacher_map", :id => 'contact_sheet' %>
7
+
8
+ <map name="teacher_map">
9
+ <area shape="rect" alt="Hawk Karissa" coords="863,274,968,430" href="#karissa"/>
10
+ <area shape="rect" alt="Karen" coords="863,64,1023,238" href="#karen"/>
11
+ <area shape="rect" alt="Cat Lucy" coords="746,0,838,199" href="#lucy"/>
12
+ <area shape="rect" alt="The Solomon" coords="759,206,852,430" href="#solomon"/>
13
+ <area shape="rect" alt="Bat Jeremy" coords="637,123,731,430" href="#jeremy"/>
14
+ <area shape="rect" alt="Super Topher" coords="376,0,600,430" href="#topher"/>
15
+ <area shape="rect" alt="Wonder Lessa" coords="265,139,355,430" href="#lessa"/>
16
+ <area shape="rect" alt="The Green Jocelyn" coords="148,221,232,430" href="#jocelyn"/>
17
+ <area shape="rect" alt="Kevin Buster" coords="44,251,132,431" href="#kevin"/>
18
+ <area shape="rect" alt="Chris Chapman" coords="22,0,231,186" href="#chris"/>
19
+ </map>
20
+
21
+ <br/>
22
+ <hr/>
23
+ <br/>
24
+
25
+ <%= teacher :chris, "Chris Chapman" %>
26
+
27
+ <%= teacher :jeremy, "Jeremy Stell-Smith", "Momentum in blues, oh...and I can kill you with my mind", "Jeremy has lived swing and blues dancing across the country and the world for the last 10 years. He brings different points of view, different dances, and above all, passion into the mix." %>
28
+
29
+ <%= teacher :jocelyn, "Jocelyn Miller", "", "Jocelyn was introduced to Blues dancing in 1999. After hours of dancing primarily on her right leg and developing a very sore right thigh (definitely not the best technique in town), she knew she was hooked. She's been reluctant to miss a Blues dance ever since. When it comes to dancing to Blues or any other music, her biggest influences and inspiration are through the music and her partner. She loves playfulness and fun, especially with a touch of sass, so make her day and bring it on!
30
+ Jocelyn currently lives in Vancouver, BC and occasionally teaches classes and workshops there." %>
31
+
32
+ <%= teacher :karen, "Karen Smith" %>
33
+
34
+ <%= teacher :karissa, "Karissa", "Solo Blues & Not Eating Meat", "Karissa is known around the country for her energy and creativity in blues dancing. She has been dancing for 6 crazy years, during which, she's travelled and danced extensively around the world.
35
+
36
+ She brings vitality, drive, and pure joy to her students." %>
37
+
38
+ <%= teacher :kevin, "Kevin Buster", "Musicality, being in this moment, solo blues, blues air movement, building a dance, and being myself. And I have a big #*%&?ng X on my chest (see above)",
39
+ "<b>Long History:</b> Check <a href='http://kevinbuster.com'>Kevin Buster.com</a> for that.<br/><br/>
40
+ <b>Recent History:</b> Kevin threw \"The First Zurich Blues Party\" when he was in Switzerland in Feb. 2008.<br/><br/>
41
+ <b>The Future:</b> Kevin will be going to New York and Hungary to teach blues and will be going to Guinea, Africa to work on African dancing to bring it to his facility and mix it with Blues movement all in the next year. Oh and of course seeing you at this event=)." %>
42
+
43
+ <%= teacher :lessa, "Lessa Jay" %>
44
+
45
+ <%= teacher :lucy, "Lucy Falkner" %>
46
+
47
+ <%= teacher :solomon, "Solomon Douglas", "Solomon Douglas is the Caffeine Spider!", "Solomon Douglas has been studying blues dancing and practising it
48
+ socially for as long as he has been lindy hopping (that is, since
49
+ 1998), and has been teaching it since 1999. He learned 40% of his
50
+ blues dancing from such luminaries as Steven Mitchell, Chachi, and
51
+ Bill Borgida, and the other 60% from thousands of hours of social
52
+ blues dancing." %>
53
+
54
+ <%= teacher :topher, "topher", "Flying, seriously" %>
@@ -0,0 +1,17 @@
1
+ require 'rubygems'
2
+
3
+ gem 'activesupport'
4
+ require 'active_support'
5
+
6
+ gem 'RedCloth'
7
+ require 'redcloth'
8
+
9
+ gem 'markaby'
10
+ require 'markaby'
11
+
12
+ require 'erb'
13
+ require 'yaml'
14
+
15
+ require 'action_site/extensions/string'
16
+
17
+ require 'action_site/site'
@@ -0,0 +1,18 @@
1
+ module ActionSite
2
+ class Context
3
+ def method_missing(sym, *args)
4
+ if sym.to_s.ends_with?("=") && args.size == 1
5
+ metaclass.send(:attr_accessor, sym.to_s[0..-2].to_sym)
6
+ send(sym, *args)
7
+ else
8
+ super
9
+ end
10
+ end
11
+
12
+ private
13
+
14
+ def metaclass
15
+ class << self; self; end # according to why...
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,13 @@
1
+ class String
2
+ def split_filename
3
+ if self =~ /^(.+)\.([^\.]+)$/
4
+ [$1, $2]
5
+ else
6
+ [self, nil]
7
+ end
8
+ end
9
+
10
+ def extension
11
+ split_filename[1]
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ module ActionSite
2
+ module Generators
3
+ class ErbGenerator
4
+ def process(context, content)
5
+ ERB.new(content, 0, "%<>").result(context.get_binding)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ module ActionSite
2
+ module Generators
3
+ class MarkabyGenerator
4
+ def process(context, content)
5
+ builder = Markaby::Builder.new({}, context)
6
+ builder.instance_eval content, context.file_name
7
+ content = builder.to_s
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ module ActionSite
2
+ module Generators
3
+ class RedclothGenerator
4
+ def process(context, content)
5
+ redcloth = RedCloth.new(content)
6
+ content = redcloth.to_html(:html, :textile)
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ module ActionSite
2
+ module Generators
3
+ class YamlGenerator
4
+ def process(context, content)
5
+ content = YAML::load(content) rescue raise("error reading #{context.file_name}: #{$!.message}")
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,6 @@
1
+ module ActionSite
2
+ module Helpers
3
+ module FormHelper
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,9 @@
1
+ module ActionSite
2
+ module Helpers
3
+ module MarkabyHelper
4
+ def markaby(&block)
5
+ Markaby::Builder.new({}, self, &block).to_s
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,26 @@
1
+ module ActionSite
2
+ module Helpers
3
+ module UrlHelper
4
+ def link_to(name, url, options = {})
5
+ options = options.map {|key, value| %{ #{key}="#{value}"}}.join
6
+ %{<a href="#{url}"#{options}>#{name}</a>}
7
+ end
8
+
9
+ def link_to_function(name, function, options = {})
10
+ options = options.map {|key, value| %{ #{key}="#{value}"}}.join
11
+ %{<a href="#" onclick="#{function};return false;"#{options}>#{name}</a>}
12
+ end
13
+
14
+ def image_tag(url, options = {})
15
+ options = options.map {|key, value| %{ #{key}="#{value}"}}.join
16
+ url = "images/#{url}" unless url =~ /^https?\:\/\//
17
+ %{<img src="#{url}"#{options}/>}
18
+ end
19
+
20
+ def stylesheet_link_tag(name, options = {})
21
+ options = options.map {|key, value| %{ #{key}="#{value}"}}.join
22
+ %{<link href="stylesheets/intro.css" rel="stylesheet" type="text/css"#{options}>}
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,41 @@
1
+ require 'action_site/page_context'
2
+
3
+ module ActionSite
4
+ class HtmlGenerator
5
+ attr_reader :template_directory
6
+
7
+ def initialize(site_context, template_directory)
8
+ @site_context, @template_directory = site_context, template_directory
9
+ end
10
+
11
+ def process_file(file, context = new_context(file), apply_layout = true)
12
+ process(File.basename(file), context, File.read(file), apply_layout)
13
+ rescue
14
+ $stderr.puts "error processing #{file}"
15
+ raise
16
+ end
17
+
18
+ def process(file_name, context, content, apply_layout = true)
19
+ file_name, extension = file_name.split_filename
20
+
21
+ generator = ActionSite.generators[extension]
22
+ if generator
23
+ content = generator.process(context, content)
24
+
25
+ elsif extension.nil?
26
+ if apply_layout && context.layout_template
27
+ context.content = content
28
+ return process_file(context.layout_template, context, false)
29
+ else
30
+ return content
31
+ end
32
+ end
33
+
34
+ return process(file_name, context, content, apply_layout)
35
+ end
36
+
37
+ def new_context(file_name = nil)
38
+ PageContext.new(self, @site_context, file_name)
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,68 @@
1
+ require 'action_site/context'
2
+
3
+ require 'action_site/helpers/form_helper'
4
+ require 'action_site/helpers/markaby_helper'
5
+ require 'action_site/helpers/url_helper'
6
+
7
+ module ActionSite
8
+ # an instance of this class is created for each page
9
+ # this is how pages can access magical things like link_to, etc
10
+ class PageContext < Context
11
+ include Helpers::FormHelper
12
+ include Helpers::UrlHelper
13
+ include Helpers::MarkabyHelper
14
+ attr_accessor :global_context, :layout_template, :pattern, :content, :file_name
15
+
16
+ def initialize(html_generator, global_context, file_name)
17
+ @html_generator, @global_context, @file_name =
18
+ html_generator, global_context, file_name
19
+ layout(:application) rescue nil
20
+ end
21
+
22
+ def layout(name)
23
+ if name
24
+ files = Dir[File.join(@html_generator.template_directory, 'layouts', "#{name}.*")]
25
+ raise "couldn't find layout #{name}" if files.empty?
26
+ @layout_template = files.first
27
+ else
28
+ @layout_template = nil
29
+ end
30
+ end
31
+
32
+ def process_file(*args)
33
+ @html_generator.process_file(*args)
34
+ end
35
+
36
+ def helper(name)
37
+ file_name = "#{name}_helper"
38
+ class_name = file_name.classify
39
+ helper = begin
40
+ class_name.constantize
41
+ rescue NameError # this constant hasn't been loaded yet
42
+ require File.join(@html_generator.template_directory, "helpers", file_name)
43
+ class_name.constantize
44
+ end
45
+
46
+ metaclass.send(:include, helper)
47
+ end
48
+
49
+ def content_for(name)
50
+ self.send("content_for_#{name}=".to_sym, yield)
51
+ end
52
+
53
+ def get_binding
54
+ binding
55
+ end
56
+
57
+ def method_missing(sym, *args)
58
+ return @global_context.send(sym, *args) if @global_context.respond_to?(sym)
59
+
60
+ name = sym.to_s
61
+ if name.starts_with?("content_for_") && name.ends_with?("?")
62
+ return !!instance_variable_get("@#{name[0..-2]}")
63
+ end
64
+
65
+ super
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,77 @@
1
+ require 'action_site/context'
2
+
3
+ require 'action_site/html_generator'
4
+
5
+ require 'action_site/generators/erb_generator'
6
+ require 'action_site/generators/markaby_generator'
7
+ require 'action_site/generators/redcloth_generator'
8
+ require 'action_site/generators/yaml_generator'
9
+
10
+ module ActionSite
11
+ EXCLUDED_DIRECTORIES = %w(layouts helpers)
12
+ RESOURCE_EXTENSIONS = %w(css ico gif jpg png js)
13
+
14
+ def self.generators
15
+ @generators ||= {
16
+ "erb" => Generators::ErbGenerator.new,
17
+ "mab" => Generators::MarkabyGenerator.new,
18
+ "red" => Generators::RedclothGenerator.new,
19
+ "yml" => Generators::YamlGenerator.new,
20
+ "yaml" => Generators::YamlGenerator.new
21
+ }
22
+ end
23
+
24
+ class Site
25
+ attr_reader :context
26
+
27
+ def initialize(in_dir, out_dir)
28
+ @context = Context.new
29
+ @generator = HtmlGenerator.new(@context, in_dir)
30
+ @in_dir, @out_dir = in_dir, out_dir
31
+ puts "\nGENERATING #{File.basename(in_dir).upcase}\n\n"
32
+ rm_rf out_dir
33
+ mkdir_p out_dir
34
+ end
35
+
36
+ def generate(in_dir = @in_dir, out_dir = @out_dir)
37
+ Dir[in_dir + "/*"].each do |in_file|
38
+ out_file = in_file.gsub(in_dir, out_dir)
39
+
40
+ if excluded?(in_file)
41
+ # nothing
42
+
43
+ elsif File.symlink?(in_file)
44
+ cp in_file, out_file rescue nil # maybe the links don't exist here
45
+
46
+ elsif File.directory?(in_file)
47
+ mkdir_p out_file
48
+ generate in_file, out_file
49
+
50
+ elsif resource?(in_file)
51
+ ln_s File.expand_path(in_file), File.expand_path(out_file)
52
+
53
+ else
54
+ out_file = out_file.gsub(/\..+$/, '.html')
55
+ generate_page(in_file, out_file)
56
+ puts " #{in_file} => #{out_file}"
57
+ end
58
+ end
59
+ end
60
+
61
+ def excluded?(file)
62
+ File.directory?(file) && EXCLUDED_DIRECTORIES.include?(File.basename(file))
63
+ end
64
+
65
+ def resource?(file)
66
+ RESOURCE_EXTENSIONS.include?(file.extension)
67
+ end
68
+
69
+ private
70
+
71
+ def generate_page(in_file, out_file)
72
+ File.open(out_file, "w") do |f|
73
+ f << @generator.process_file(in_file)
74
+ end
75
+ end
76
+ end
77
+ end
File without changes
@@ -0,0 +1,16 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ module ActionSite
4
+ describe Context do
5
+ it "should allow setting new variables and accessing them" do
6
+ context = Context.new
7
+ context.foo = "bar"
8
+ context.foo.should == "bar"
9
+ end
10
+
11
+ it "should complain if accessing a variable it doesn't know about" do
12
+ context = Context.new
13
+ proc {context.foo}.should raise_error
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe String do
4
+ it "should know how to separate it's extension" do
5
+ "some file called.txt".split_filename.should == ["some file called", "txt"]
6
+ "a.html.erb".split_filename.should == ["a.html", "erb"]
7
+ "a.pdf.html.erb".split_filename.should == ["a.pdf.html", "erb"]
8
+ "apple".split_filename.should == ["apple", nil]
9
+ end
10
+
11
+ it "should know it's extension" do
12
+ "a.txt".extension.should == "txt"
13
+ "a.html.erb".extension.should == "erb"
14
+ "apple".extension.should == nil
15
+ end
16
+ end
@@ -0,0 +1,7 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe ActionSite::Helpers::FormHelper do
4
+ include ActionSite::Helpers::FormHelper
5
+
6
+
7
+ end
@@ -0,0 +1,45 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe ActionSite::Helpers::UrlHelper do
4
+ include ActionSite::Helpers::UrlHelper
5
+
6
+ describe "#link_to" do
7
+ it "should show a link" do
8
+ link_to_function("foo", "alert('you')").should ==
9
+ %{<a href="#" onclick="alert('you');return false;">foo</a>}
10
+ end
11
+ end
12
+
13
+ describe "#link_to" do
14
+ it "should show a link" do
15
+ link_to("foo", "http://google.com").should ==
16
+ '<a href="http://google.com">foo</a>'
17
+ end
18
+
19
+ it "should put optional params into the html" do
20
+ link_to("a", "/b", :class => "my").should == '<a href="/b" class="my">a</a>'
21
+ link_to("a", "/b", :size => 5).should == '<a href="/b" size="5">a</a>'
22
+ end
23
+ end
24
+
25
+ describe "#image_tag" do
26
+ it "should show an image from images/" do
27
+ image_tag("foo.png").should == %{<img src="images/foo.png"/>}
28
+ end
29
+
30
+ it "should not prepend images/ to fully qualified urls" do
31
+ image_tag("http://foo/foo.png").should == %{<img src="http://foo/foo.png"/>}
32
+ end
33
+
34
+ it "should show an image" do
35
+ image_tag("foo.png", :class => 'foo').should == %{<img src="images/foo.png" class="foo"/>}
36
+ end
37
+ end
38
+
39
+ describe "#stylesheet_link_tag" do
40
+ it "should work" do
41
+ stylesheet_link_tag(:intro, :media => :all).should ==
42
+ '<link href="stylesheets/intro.css" rel="stylesheet" type="text/css" media="all">'
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,114 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe ActionSite::HtmlGenerator do
4
+ include FileSandbox
5
+ attr_reader :generator
6
+
7
+ before do
8
+ @generator = ActionSite::HtmlGenerator.new(ActionSite::Context.new, sandbox.root)
9
+ end
10
+
11
+ describe "default generators" do
12
+ it "should have erb, mab, yaml, red" do
13
+ ActionSite.generators.keys.sort.should == %w(erb mab red yaml yml)
14
+ end
15
+ end
16
+
17
+ describe "layouts" do
18
+ it "should show html w/ default layout" do
19
+ sandbox.new :file => 'layouts/application.html.erb',
20
+ :with_contents => "<html><body><%= content %></body></html>"
21
+
22
+ process("*.html", "foobar").should == "<html><body>foobar</body></html>"
23
+ end
24
+
25
+ it "should be able to specify a layout" do
26
+ sandbox.new :file => 'layouts/my_layout.html.erb',
27
+ :with_contents => "<html><%= content %></html>"
28
+
29
+ process("*.html.erb", "% layout 'my_layout'\nfoobar").should ==
30
+ "<html>foobar</html>"
31
+ process("*.html.erb", "% layout :my_layout\nfoobar").should ==
32
+ "<html>foobar</html>"
33
+ end
34
+
35
+ it "should forget about layout after layout is specified" do
36
+ sandbox.new :file => 'layouts/application.html.erb', :with_contents => "app"
37
+ sandbox.new :file => 'layouts/foo.html.erb', :with_contents => "foo"
38
+
39
+ process("*.html", "").should == "app"
40
+ process("*.html.erb", "% layout 'foo'").should == "foo"
41
+ process("*.html", "").should == "app"
42
+ end
43
+
44
+ it "should allow a nil layout" do
45
+ process("*.html.erb", "% layout nil\nsomething").should == "something"
46
+ process("*.html.erb", "% layout false\nsomething").should == "something"
47
+ end
48
+ end
49
+
50
+ describe "helpers" do
51
+ before do
52
+ sandbox.new :file => 'helpers/test_helper.rb', :with_contents => "
53
+ module TestHelper
54
+ def some_test_method
55
+ 'hello world'
56
+ end
57
+ end"
58
+ sandbox.new :file => "layouts/application.html.erb",
59
+ :with_contents => "<%= content %>"
60
+ end
61
+
62
+ it "should be able to use a helper" do
63
+ process("*.html.erb", "% helper 'test'\n<%= some_test_method %>").
64
+ should == "hello world"
65
+ end
66
+ end
67
+
68
+ describe "content_for" do
69
+ it "should remember a string value" do
70
+ sandbox.new :file => "layouts/application.html.erb",
71
+ :with_contents => "head:<%= content_for_head %>"
72
+ process("*.html.erb", "% content_for(:head) { 'bob' }").should == "head:bob"
73
+ end
74
+
75
+ it "should know if there is content for a given key" do
76
+ sandbox.new :file => "layouts/application.html.erb",
77
+ :with_contents => "head:<%= content_for_head? %>, tail:<%= content_for_tail? %>"
78
+
79
+ process("*.html.erb", "").should == "head:false, tail:false"
80
+ process("*.html.erb", "% content_for(:tail) { 'a' }").should == "head:false, tail:true"
81
+ process("*.html.erb", "% content_for(:head) { 'bob' }\n% content_for(:tail) {'a'}").should == "head:true, tail:true"
82
+ end
83
+ end
84
+
85
+ describe "markaby" do
86
+ it "should generate html from markaby" do
87
+ process("*.mab", <<-MAB).should == %{<div class="foo">8</div>}
88
+ div.foo do
89
+ text 5 + 3
90
+ end
91
+ MAB
92
+ end
93
+
94
+ it "should be able to have markaby w/in markaby" do
95
+ process("*.mab", <<-MAB).should == %{<div class="foo"><i>photo</i></div>}
96
+ def bob
97
+ markaby do
98
+ i { "photo" }
99
+ end
100
+ end
101
+
102
+ div.foo do
103
+ bob
104
+ end
105
+ MAB
106
+ end
107
+ end
108
+
109
+ def process(extensions, content)
110
+ generator.process(extensions,
111
+ generator.new_context(extensions),
112
+ content)
113
+ end
114
+ end
@@ -0,0 +1,32 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ module ActionSite
4
+ describe PageContext do
5
+ attr_reader :context
6
+
7
+ before do
8
+ @context = PageContext.new(nil, nil, nil)
9
+ end
10
+
11
+ it "should allow setting new variables and accessing them" do
12
+ context.foo = "bar"
13
+ context.foo.should == "bar"
14
+ end
15
+
16
+ describe "#content_for" do
17
+ it "should handle content for w/ simple block" do
18
+ context.content_for("me") { "your mom" }
19
+
20
+ context.content_for_me.should == "your mom"
21
+ end
22
+
23
+ it "should know if a content_for_block has been specified" do
24
+ context.content_for_me?.should == false
25
+
26
+ context.content_for("me") { "your mom" }
27
+
28
+ context.content_for_me?.should == true
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,8 @@
1
+ $LOAD_PATH << File.expand_path(File.dirname(__FILE__) + "/../lib")
2
+ require "action_site"
3
+
4
+ gem 'rspec'
5
+ require 'spec'
6
+
7
+ gem 'file_sandbox', '>= 0.4'
8
+ require 'file_sandbox_behavior'
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jeremylightsmith-actionsite
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.1"
5
+ platform: ruby
6
+ authors:
7
+ - Jeremy Lightsmith
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-11-12 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activesupport
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">"
21
+ - !ruby/object:Gem::Version
22
+ version: 0.0.0
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: RedCloth
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">"
30
+ - !ruby/object:Gem::Version
31
+ version: 0.0.0
32
+ version:
33
+ - !ruby/object:Gem::Dependency
34
+ name: markaby
35
+ version_requirement:
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.0.0
41
+ version:
42
+ description: ActionSite is a static site generator for ruby patterned after rails view templates supporting erb, yaml, redcloth and markaby(ish).
43
+ email: jeremy.lightsmith@gmail.com
44
+ executables: []
45
+
46
+ extensions: []
47
+
48
+ extra_rdoc_files: []
49
+
50
+ files:
51
+ - Rakefile
52
+ - readme.txt
53
+ - lib/action_site
54
+ - lib/action_site/context.rb
55
+ - lib/action_site/extensions
56
+ - lib/action_site/extensions/string.rb
57
+ - lib/action_site/generators
58
+ - lib/action_site/generators/erb_generator.rb
59
+ - lib/action_site/generators/markaby_generator.rb
60
+ - lib/action_site/generators/redcloth_generator.rb
61
+ - lib/action_site/generators/yaml_generator.rb
62
+ - lib/action_site/helpers
63
+ - lib/action_site/helpers/form_helper.rb
64
+ - lib/action_site/helpers/markaby_helper.rb
65
+ - lib/action_site/helpers/url_helper.rb
66
+ - lib/action_site/html_generator.rb
67
+ - lib/action_site/page_context.rb
68
+ - lib/action_site/site.rb
69
+ - lib/action_site.rb
70
+ - example/src/helpers
71
+ - example/src/helpers/blues_hero_helper.rb
72
+ - example/src/images
73
+ - example/src/images/batjeremy.jpg
74
+ - example/src/images/black_header.png
75
+ - example/src/images/black_header_with_slogan.png
76
+ - example/src/images/chris.jpg
77
+ - example/src/images/hawk-karissa.png
78
+ - example/src/images/header.png
79
+ - example/src/images/jeremy.jpg
80
+ - example/src/images/jocelyn.jpg
81
+ - example/src/images/karen.jpg
82
+ - example/src/images/karissa.jpg
83
+ - example/src/images/kevin.jpg
84
+ - example/src/images/lessa.jpg
85
+ - example/src/images/lucy.jpg
86
+ - example/src/images/menu_bar.png
87
+ - example/src/images/simple_header.png
88
+ - example/src/images/solomon.jpg
89
+ - example/src/images/supertopher.jpg
90
+ - example/src/images/supertopher_and_batjeremy.jpg
91
+ - example/src/images/teacher_contact_sheet.jpg
92
+ - example/src/images/topher.jpg
93
+ - example/src/index.html.erb
94
+ - example/src/layouts
95
+ - example/src/layouts/application.html.erb
96
+ - example/src/register.html.erb
97
+ - example/src/schedule.html.erb
98
+ - example/src/stylesheets
99
+ - example/src/stylesheets/application.css
100
+ - example/src/teachers.html.erb
101
+ has_rdoc: false
102
+ homepage: http://github.com/jeremylightsmith/actionsite
103
+ post_install_message:
104
+ rdoc_options: []
105
+
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: "0"
113
+ version:
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: "0"
119
+ version:
120
+ requirements: []
121
+
122
+ rubyforge_project:
123
+ rubygems_version: 1.2.0
124
+ signing_key:
125
+ specification_version: 2
126
+ summary: A static site generator patterned after rails view templates supporting erb, yaml, redcloth and markaby(ish)
127
+ test_files:
128
+ - spec/action_site
129
+ - spec/action_site/context_spec.rb
130
+ - spec/action_site/extensions
131
+ - spec/action_site/extensions/string_spec.rb
132
+ - spec/action_site/helpers
133
+ - spec/action_site/helpers/form_helper_spec.rb
134
+ - spec/action_site/helpers/url_helper_spec.rb
135
+ - spec/action_site/html_generator_spec.rb
136
+ - spec/action_site/page_context_spec.rb
137
+ - spec/spec_helper.rb