webby 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/History.txt +3 -0
  2. data/Manifest.txt +44 -0
  3. data/README.txt +50 -0
  4. data/Rakefile +29 -0
  5. data/bin/webby +14 -0
  6. data/data/Rakefile +6 -0
  7. data/data/content/css/blueprint/License.txt +21 -0
  8. data/data/content/css/blueprint/Readme.txt +93 -0
  9. data/data/content/css/blueprint/lib/buttons.css +112 -0
  10. data/data/content/css/blueprint/lib/compressed.css +127 -0
  11. data/data/content/css/blueprint/lib/grid.css +177 -0
  12. data/data/content/css/blueprint/lib/img/baseline-black.png +0 -0
  13. data/data/content/css/blueprint/lib/img/baseline.png +0 -0
  14. data/data/content/css/blueprint/lib/img/grid.png +0 -0
  15. data/data/content/css/blueprint/lib/img/icons/cross.png +0 -0
  16. data/data/content/css/blueprint/lib/img/icons/textfield_key.png +0 -0
  17. data/data/content/css/blueprint/lib/img/icons/tick.png +0 -0
  18. data/data/content/css/blueprint/lib/reset.css +37 -0
  19. data/data/content/css/blueprint/lib/typography.css +159 -0
  20. data/data/content/css/blueprint/print.css +75 -0
  21. data/data/content/css/blueprint/screen.css +34 -0
  22. data/data/content/css/site.css +0 -0
  23. data/data/content/index.rhtml +18 -0
  24. data/data/layouts/default.rhtml +55 -0
  25. data/data/tasks/create.rake +7 -0
  26. data/data/templates/page.erb +18 -0
  27. data/lib/webby.rb +67 -0
  28. data/lib/webby/auto_builder.rb +75 -0
  29. data/lib/webby/builder.rb +165 -0
  30. data/lib/webby/file.rb +191 -0
  31. data/lib/webby/main.rb +129 -0
  32. data/lib/webby/pages_db.rb +70 -0
  33. data/lib/webby/renderer.rb +94 -0
  34. data/lib/webby/resource.rb +174 -0
  35. data/lib/webby/utils.rb +24 -0
  36. data/lib/webby/webby_task.rb +136 -0
  37. data/spec/spec.opts +1 -0
  38. data/spec/spec_helper.rb +12 -0
  39. data/spec/webby/file_spec.rb +107 -0
  40. data/tasks/doc.rake +60 -0
  41. data/tasks/gem.rake +112 -0
  42. data/tasks/manifest.rake +39 -0
  43. data/tasks/setup.rb +108 -0
  44. data/tasks/spec.rake +37 -0
  45. metadata +128 -0
@@ -0,0 +1,34 @@
1
+ /* --------------------------------------------------------------
2
+
3
+ Blueprint CSS Framework
4
+ [bjorkoy.com/blueprint]
5
+
6
+ * Screen & Projection Styles *
7
+
8
+ This is the main CSS-file for the framework.
9
+ Include this in the <head> of every page. See the
10
+ Readme file in this directory for further instructions.
11
+
12
+ -------------------------------------------------------------- */
13
+
14
+ /* Import stylesheets and hide from IE/Mac \*/
15
+ @import "lib/reset.css";
16
+ @import "lib/typography.css";
17
+ @import "lib/grid.css";
18
+ @import "lib/buttons.css";
19
+ /* End import/hide */
20
+
21
+
22
+ /* Compressed version:
23
+ [http://teenage.cz/acidofil/tools/cssformat.php]
24
+
25
+ Comment out @import statements above, and add this
26
+ one when your site has launched (Ca 60% compressed):
27
+ @import "lib/compressed.css"; */
28
+
29
+
30
+ /* Uncomment the line below to see the grid and baseline.
31
+ (Assuming you've wrapped your columns in a container).
32
+
33
+ .container { background: url(lib/img/grid.png); }
34
+ .container { background: url(lib/img/baseline.png); } */
File without changes
@@ -0,0 +1,18 @@
1
+ ---
2
+ title: Home Page
3
+ filter:
4
+ - erb
5
+ - textile
6
+ ---
7
+ h2. <%= @page.title %>
8
+
9
+ Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nunc congue ipsum vestibulum libero. Aenean vitae justo. Nam eget tellus. Etiam convallis, est eu lobortis mattis, lectus tellus tempus felis, a ultricies erat ipsum at metus.
10
+
11
+ h3. Litora Sociis
12
+
13
+ Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Morbi et risus. Aliquam nisl. Nulla facilisi. Cras accumsan vestibulum ante. Vestibulum sed tortor. Praesent tempus fringilla elit. Ut elit diam, sagittis in, nonummy in, gravida non, nunc. Ut orci. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos hymenaeos. Nam egestas, orci eu imperdiet malesuada, nisl purus fringilla odio, quis commodo est orci vitae justo. Aliquam placerat odio tincidunt nulla. Cras in libero. Aenean rutrum, magna non tristique posuere, erat odio eleifend nisl, non convallis est tortor blandit ligula. Nulla id augue.
14
+
15
+ bq. Nullam mattis, odio ut tempus facilisis, metus nisl facilisis metus, auctor consectetuer felis ligula nec mauris. Vestibulum odio erat, fermentum at, commodo vitae, ultrices et, urna. Mauris vulputate, mi pulvinar sagittis condimentum, sem nulla aliquam velit, sed imperdiet mi purus eu magna. Nulla varius metus ut eros. Aenean aliquet magna eget orci. Class aptent taciti sociosqu ad litora.
16
+
17
+ Vivamus euismod. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Suspendisse vel nibh ut turpis dictum sagittis. Aliquam vel velit a elit auctor sollicitudin. Nam vel dui vel neque lacinia pretium. Quisque nunc erat, venenatis id, volutpat ut, scelerisque sed, diam. Mauris ante. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Donec mattis. Morbi dignissim sollicitudin libero. Nulla lorem.
18
+
@@ -0,0 +1,55 @@
1
+ ---
2
+ extension: html
3
+ filter: erb
4
+ ---
5
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
6
+ "DTD/xhtml1-strict.dtd">
7
+
8
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en-us">
9
+ <head>
10
+ <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
11
+ <title><%= @page.title %></title>
12
+ <meta name="author" content="<%= @page.author %>" />
13
+
14
+ <!--- Blueprint CSS Framework -->
15
+ <link rel="stylesheet" href="css/blueprint/screen.css" type="text/css" media="screen, projection" />
16
+ <link rel="stylesheet" href="css/blueprint/print.css" type="text/css" media="print" />
17
+
18
+ <!-- Homepage CSS -->
19
+ <link rel="stylesheet" href="css/site.css" type="text/css" media="screen, projection" />
20
+ </head>
21
+ <body>
22
+
23
+ <div class="container">
24
+
25
+ <div class="column span-11 prepend-1 first last">
26
+ <h2>A New Website</h2>
27
+ <hr>
28
+ </div>
29
+
30
+ <div class="column span-8 prepend-1 first">
31
+ <%= @content %>
32
+ </div>
33
+
34
+ <div class="column span-3 last">
35
+ <h4>Sidebar</h4>
36
+ <p>Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Cras ornare mattis nunc. Mauris venenatis, pede sed aliquet vehicula, lectus tellus pulvinar neque, non cursus sem nisi vel augue. </p>
37
+
38
+ <div class="box">
39
+ <p class="last">Mauris a lectus. Aliquam erat volutpat. Phasellus ultrices mi a sapien. Nunc rutrum egestas lorem. Duis ac sem sagittis elit tincidunt gravida.</p>
40
+ </div>
41
+
42
+ <p class="quiet">Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Cras ornare mattis nunc. Mauris venenatis, pede sed aliquet vehicula, lectus tellus pulvinar neque, non cursus sem nisi vel augue.</p>
43
+
44
+ <h5>Incremental leading</h5>
45
+ <p class="incr">Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Cras ornare mattis nunc. Mauris venenatis, pede sed aliquet vehicula, lectus tellus pulvinar neque, non cursus sem nisi vel augue. sed aliquet vehicula, lectus tellus.</p>
46
+ </div>
47
+
48
+ <div class="column span-11 prepend-1 first last">
49
+ <hr />
50
+ <p>This website was created with <a href="http://webby.rubyforge.org">Webby</a></p>
51
+ </div>
52
+
53
+ </div>
54
+ </body>
55
+ </html>
@@ -0,0 +1,7 @@
1
+
2
+ require 'webby'
3
+
4
+ Rake::WebbyTask.new do |webby|
5
+ webby.output_dir = 'output'
6
+ end
7
+
@@ -0,0 +1,18 @@
1
+ ---
2
+ title: New Page
3
+ created_at: <%= Time.now %>
4
+ filter:
5
+ - erb
6
+ - textile
7
+ ---
8
+ h2. <%%= @page.title %>
9
+
10
+ Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nunc congue ipsum vestibulum libero. Aenean vitae justo. Nam eget tellus. Etiam convallis, est eu lobortis mattis, lectus tellus tempus felis, a ultricies erat ipsum at metus.
11
+
12
+ h3. Litora Sociis
13
+
14
+ Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Morbi et risus. Aliquam nisl. Nulla facilisi. Cras accumsan vestibulum ante. Vestibulum sed tortor. Praesent tempus fringilla elit. Ut elit diam, sagittis in, nonummy in, gravida non, nunc. Ut orci. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos hymenaeos. Nam egestas, orci eu imperdiet malesuada, nisl purus fringilla odio, quis commodo est orci vitae justo. Aliquam placerat odio tincidunt nulla. Cras in libero. Aenean rutrum, magna non tristique posuere, erat odio eleifend nisl, non convallis est tortor blandit ligula. Nulla id augue.
15
+
16
+ bq. Nullam mattis, odio ut tempus facilisis, metus nisl facilisis metus, auctor consectetuer felis ligula nec mauris. Vestibulum odio erat, fermentum at, commodo vitae, ultrices et, urna. Mauris vulputate, mi pulvinar sagittis condimentum, sem nulla aliquam velit, sed imperdiet mi purus eu magna. Nulla varius metus ut eros. Aenean aliquet magna eget orci. Class aptent taciti sociosqu ad litora.
17
+
18
+ Vivamus euismod. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Suspendisse vel nibh ut turpis dictum sagittis. Aliquam vel velit a elit auctor sollicitudin. Nam vel dui vel neque lacinia pretium. Quisque nunc erat, venenatis id, volutpat ut, scelerisque sed, diam. Mauris ante. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Donec mattis. Morbi dignissim sollicitudin libero. Nulla lorem.
@@ -0,0 +1,67 @@
1
+ # $Id: webby.rb 8 2007-08-22 22:32:09Z tim_pease $
2
+
3
+ module Webby
4
+
5
+ VERSION = '0.1.0' # :nodoc:
6
+
7
+ # Path to the Webby package
8
+ PATH = ::File.expand_path(::File.join(::File.dirname(__FILE__), '..'))
9
+
10
+ class Error < StandardError; end # :nodoc:
11
+
12
+ # call-seq:
13
+ # Webby.require_all_libs_relative_to( filename, directory = nil )
14
+ #
15
+ # Utility method used to rquire all files ending in .rb that lie in the
16
+ # directory below this file that has the same name as the filename passed
17
+ # in. Optionally, a specific _directory_ name can be passed in such that
18
+ # the _filename_ does not have to be equivalent to the directory.
19
+ #
20
+ def self.require_all_libs_relative_to( fname, dir = nil )
21
+ dir ||= File.basename(fname, '.*')
22
+ search_me = File.expand_path(
23
+ File.join(File.dirname(fname), dir, '**', '*.rb'))
24
+
25
+ Dir.glob(search_me).sort.each {|rb| require rb}
26
+ end
27
+
28
+ # call-seq:
29
+ # Webby.config => hash
30
+ #
31
+ # Returns the configuration hash for the Webby application.
32
+ #--
33
+ # The defaults are defined in the lib/webby/webby_task.rb file
34
+ #++
35
+ def self.config
36
+ @config ||= {}
37
+ end
38
+
39
+ # call-seq:
40
+ # Webby.page_defaults => hash
41
+ #
42
+ # Returns the page defaults hash used for page resource objects.
43
+ #--
44
+ # The defaults are defined in the lib/webby/webby_task.rb file
45
+ #++
46
+ def self.page_defaults
47
+ @page_defaults ||= {}
48
+ end
49
+
50
+ end # module Webby
51
+
52
+
53
+ # call-seq:
54
+ # try_require( library )
55
+ #
56
+ # Try to laod the given _library_ using the built-in require, but do not
57
+ # raise a LoadError if unsuccessful.
58
+ #
59
+ def try_require( lib )
60
+ require lib
61
+ rescue LoadError
62
+ end
63
+
64
+
65
+ Webby.require_all_libs_relative_to __FILE__
66
+
67
+ # EOF
@@ -0,0 +1,75 @@
1
+ # $Id: auto_builder.rb 5 2007-08-22 04:25:49Z tim_pease $
2
+
3
+ require 'directory_watcher'
4
+
5
+ module Webby
6
+
7
+ # The AutoBuilder class is used to monitor the content and layouts folders
8
+ # and to compile the resource files only when they are modified. If a
9
+ # layout is modified, then all resources that depend upon the layout are
10
+ # compiled.
11
+ #
12
+ class AutoBuilder
13
+
14
+ # call-seq:
15
+ # AutoBuilder.run
16
+ #
17
+ # Creates a new AutoBuilder and sets it running. This method will only
18
+ # return when the user presses Ctrl-C.
19
+ #
20
+ def self.run
21
+ self.new.run
22
+ end
23
+
24
+ # call-seq:
25
+ # AutoBuilder.new
26
+ #
27
+ # Create a new AutoBuilder class.
28
+ #
29
+ def initialize
30
+ @watcher = DirectoryWatcher.new '.', :interval => 2
31
+ @watcher.add_observer self
32
+
33
+ glob = []
34
+ glob << File.join(::Webby.config['layout_dir'], '**', '*')
35
+ glob << File.join(::Webby.config['content_dir'], '**', '*')
36
+ @watcher.glob = glob
37
+ end
38
+
39
+ # call-seq:
40
+ # update( *events )
41
+ #
42
+ # The update method is called by the DirectoryWatcher when files have been
43
+ # modified, added, or deleted. An array of events is passed to his method,
44
+ # and each event contains the event type and the path to the file.
45
+ #
46
+ def update( *events )
47
+ ary = events.find_all {|evt| evt.type != :removed}
48
+ return if ary.empty?
49
+
50
+ print '- started at '
51
+ puts Time.now.strftime('%H:%M:%S')
52
+ Builder.run
53
+ rescue => err
54
+ puts err.message
55
+ end
56
+
57
+ # call-seq:
58
+ # run
59
+ #
60
+ # Starts the DirectoryWatcher running and waits till the user presses
61
+ # Ctrl-C to stop the watcher thread.
62
+ #
63
+ def run
64
+ puts '-- starting autobuild (Ctrl-C to stop)'
65
+
66
+ Signal.trap('INT') {@watcher.stop}
67
+
68
+ @watcher.start
69
+ @watcher.join
70
+ end
71
+
72
+ end # class AutoBuilder
73
+ end # module Webby
74
+
75
+ # EOF
@@ -0,0 +1,165 @@
1
+ # $Id: builder.rb 5 2007-08-22 04:25:49Z tim_pease $
2
+
3
+ require 'find'
4
+ require 'fileutils'
5
+ require 'erb'
6
+
7
+ module Webby
8
+
9
+ # The Builder class performs the work of scanning the content folder,
10
+ # creating Resource objects, and converting / copying the contents to the
11
+ # output folder as needed.
12
+ #
13
+ class Builder
14
+
15
+ class << self
16
+
17
+ # call-seq:
18
+ # Builder.run( :rebuild => false )
19
+ #
20
+ # Create a new instance of the Builder class and invoke the run method.
21
+ # If the <code>:rebuild</code> option is given as +true+, then all pages
22
+ # will be recreated / copied.
23
+ #
24
+ def run( opts = {} )
25
+ self.new.run opts
26
+ end
27
+
28
+ # call-seq:
29
+ # Builder.create( page, :from => template )
30
+ #
31
+ # This mehod is used to create a new _page_ in the content folder based
32
+ # on the specified template. _page_ is the relative path to the new page
33
+ # from the <code>content/</code> folder. The _template_ is the name of
34
+ # the template to use from the <code>templates/</code> folder.
35
+ #
36
+ def create( page, opts = {} )
37
+ tmpl = opts[:from]
38
+ raise Error, "template not given" unless tmpl
39
+ raise Error, "#{page} already exists" if test ?e, page
40
+
41
+ puts "creating #{page}"
42
+ FileUtils.mkdir_p File.dirname(page)
43
+ str = ERB.new(::File.read(tmpl), nil, '-').result
44
+ ::File.open(page, 'w') {|fd| fd.write str}
45
+
46
+ return nil
47
+ end
48
+ end # class << self
49
+
50
+ # call-seq:
51
+ # run( :rebuild => false )
52
+ #
53
+ # Runs the Webby builder by loading in the layout files from the
54
+ # <code>layouts/</code> folder and the content from the
55
+ # <code>contents/</code> folder. Content is analyzed, and those that need
56
+ # to be copied or compiled (filtered using ERB, Texttile, Markdown, etc.)
57
+ # are handled. The results are placed in the <code>output/</code> folder.
58
+ #
59
+ # If the <code>:rebuild</code> flag is set to +true+, then all content is
60
+ # copied and/or compiled to the output folder.
61
+ #
62
+ # A content file can mark itself as dirty by setting the +dirty+ flag to
63
+ # +true+ in the meta-data of the file. This will cause the contenet to
64
+ # always be compiled when the builder is run. Conversely, setting the
65
+ # dirty flag to +false+ will cause the content to never be compiled or
66
+ # copied to the output folder.
67
+ #
68
+ # A content file needs to be built if the age of the file is less then the
69
+ # age of the output product -- i.e. the content file has been modified
70
+ # more recently than the output file.
71
+ #
72
+ def run( opts = {} )
73
+ Resource.clear
74
+
75
+ unless test(?d, output_dir)
76
+ puts "creating #{output_dir}"
77
+ FileUtils.mkdir output_dir
78
+ end
79
+
80
+ load_layouts
81
+ load_content
82
+
83
+ Resource.pages.each do |page|
84
+ next unless page.dirty? or opts[:rebuild]
85
+
86
+ puts "creating #{page.destination}"
87
+
88
+ # make sure the directory exists
89
+ FileUtils.mkdir_p ::File.dirname(page.destination)
90
+
91
+ # copy the resource to the output directory if it is static
92
+ if page.is_static?
93
+ FileUtils.cp page.path, page.destination
94
+
95
+ # otherwise, layout the resource and write the results to
96
+ # the output directory
97
+ else
98
+ ::File.open(page.destination, 'w') do |fd|
99
+ fd.write Renderer.new(page).layout_page
100
+ end
101
+ end
102
+ end
103
+
104
+ # touch the output directory so we know when the
105
+ # website was last generated
106
+ FileUtils.touch output_dir
107
+
108
+ return nil
109
+ end
110
+
111
+
112
+ private
113
+
114
+ # Scan the <code>layouts/</code> folder and create a new Resource object
115
+ # for each file found there.
116
+ #
117
+ def load_layouts
118
+ excl = Regexp.new exclude.join('|')
119
+
120
+ ::Find.find(layout_dir) do |path|
121
+ next unless test ?f, path
122
+ next if path =~ excl
123
+ Resource.new path
124
+ end
125
+
126
+ layouts = Resource.layouts
127
+
128
+ # look for loops in the layout references -- i.e. a layout
129
+ # eventually refers back to itself
130
+ layouts.each do |lyt|
131
+ stack = []
132
+ while lyt
133
+ if stack.include? lyt.filename
134
+ stack << lyt.filename
135
+ raise Error,
136
+ "loop detected in layout references: #{stack.join(' > ')}"
137
+ end
138
+ stack << lyt.filename
139
+ lyt = layouts.find_by_name lyt.layout
140
+ end # while
141
+ end # each
142
+ end
143
+
144
+ # Scan the <code>content/</code> folder and create a new Resource object
145
+ # for each file found there.
146
+ #
147
+ def load_content
148
+ excl = Regexp.new exclude.join('|')
149
+ Find.find(content_dir) do |path|
150
+ next unless test ?f, path
151
+ next if path =~ excl
152
+ Resource.new path, ::Webby.page_defaults
153
+ end
154
+ end
155
+
156
+ %w(output_dir layout_dir content_dir exclude).each do |key|
157
+ self.class_eval <<-CODE
158
+ def #{key}( ) ::Webby.config['#{key}'] end
159
+ CODE
160
+ end
161
+
162
+ end # class Builder
163
+ end # module Webby
164
+
165
+ # EOF