Skip to content
Browse files

More work on web site

  • Loading branch information...
1 parent d16d9eb commit a880da80e804a7048424d46fbe99eb1d5dcf20b1 @winton committed
Showing with 9,066 additions and 60 deletions.
  1. +49 −48 README.md
  2. +24 −6 site/controller.rb
  3. +2 −1 site/index.html.haml
  4. +8,982 −0 site/jquery-1.6.2.js
  5. +9 −5 site/stasis.css.scss
View
97 README.md
@@ -16,53 +16,49 @@ Install via RubyGems:
$ gem install stasis
-Verify the install:
-
-<!-- language:console -->
-
- $ stasis -h
-
Templates
---------
+At its most essential, Stasis takes a directory tree with [supported template files](#supported_markup_languages) and renders them.
+
Example directory structure:
<!-- language:console -->
project/
index.html.haml
- subdirectory/
- index.html.haml
- other.txt
+ other.txt
-Open terminal and run `stasis`:
+Run `stasis`:
-<!-- language:console -->
+<!-- highlight:stasis language:console -->
$ cd project
$ stasis
-You now have a `public` directory:
+Stasis creates a `public` directory:
-<!-- language:console -->
+<!-- highlight:public/ language:console -->
project/
+ index.html.haml
+ other.txt
public/
index.html
- subdirectory/
- index.html
- other.txt
+ other.txt
-Templates (`*.html.haml`) are rendered and the template extension is removed.
+`index.html.haml` renders to `public/index.html`.
-Because `.txt` is not a supported template extension, Stasis copies `other.txt` and does nothing further to it.
+`other.txt` is copied as-is because `.txt` is an unrecognized template extension.
Controllers
-----------
-Let's add controllers to the project:
+Controllers contain Ruby code that is evaluated once before all templates render.
-<!-- language:console -->
+Example directory structure:
+
+<!-- highlight:controller.rb language:console -->
project/
controller.rb
@@ -70,32 +66,35 @@ Let's add controllers to the project:
subdirectory/
controller.rb
index.html.haml
- other.txt
-
-Each controller executes once before rendering templates at the same directory level or below.
Before
------
-In your controller:
+Use `before` blocks within your `controller.rb` to execute code before templates render.
+
+`controller.rb`:
before 'index.html.haml' do
@something = true
end
-The class variable `@something` is made available to the `index.html.haml` template.
+`@something` is now available to the `index.html.haml` template.
-The `before` method can take any number of paths and/or regular expressions.
+The `before` method can take any number of paths and/or regular expressions:
+
+ before 'index.html.haml', /.*html.erb/ do
+ @something = true
+ end
Layouts
-------
-Create a `layout.html.haml` template:
+`layout.html.haml`:
%html
%body= yield
-In your controller, set the default layout:
+In your `controller.rb`, set the default layout:
layout 'layout.html.haml'
@@ -103,25 +102,16 @@ Set the layout for a particular template:
layout 'index.html.haml' => 'layout.html.haml'
-Or use a regular expression:
+Use a regular expression:
- layout /.*.html.haml/ => 'layout.html.haml'
+ layout /.*html.haml/ => 'layout.html.haml'
-Set the layout from a `before` filter if you like:
+Set the layout from a `before` block:
before 'index.html.haml' do
layout 'layout.html.haml'
end
-Ignore
-------
-
-Use the `ignore` method in your controller to ignore certain paths.
-
-For example, to ignore paths with an underscore at the beginning (partials):
-
- ignore /_.*/
-
Render
------
@@ -160,7 +150,7 @@ The `instead` method changes the output of the template being rendered:
Helpers
-------
-To make methods available to `before` callbacks and templates, add a `helpers` block to your controller:
+`controller.rb`:
helpers do
def say_hello
@@ -168,27 +158,38 @@ To make methods available to `before` callbacks and templates, add a `helpers` b
end
end
+The `say_hello` method is now available to all `before` blocks and templates.
+
+Ignore
+------
+
+Use the `ignore` method in your `controller.rb` to ignore certain paths.
+
+Ignore filenames with an underscore at the beginning:
+
+ ignore /_.*/
+
Priority
--------
-Change the order in which files are rendered or copied:
+Use the `priority` method in your `controller.rb` to change the file process order.
- priority 'index.html.erb' => 1, /.*\.txt/ => 2
+Copy `.txt` files before rendering `index.html.erb`:
-In this example, text files are copied to `public` before `index.html.erb` renders.
+ priority /.*txt/ => 2, 'index.html.erb' => 1
-The default priority is `0`.
+The default priority is `0` for all files.
More
----
-### Automatic Regeneration
+### Development Mode
To continuously regenerate your project as you modify files, run:
-<!-- language:console -->
+<!-- highlight:-d language:console -->
- $ stasis -a
+ $ stasis -d
### Supported Markup Languages
View
30 site/controller.rb
@@ -10,22 +10,32 @@
node.remove
end
- # Link <h2> tags
- @links = @readme.css('h2').collect do |node|
- href = node.text.downcase
+ # Link <h2> and <h3> tags
+ @links = @readme.css('h2, h3').collect do |node|
+ href = node.text.downcase.gsub(/\s/, '_')
name = node.text
node.inner_html = '<a name="' + href + '" href="#' + href + '">' + node.inner_html + '</a>'
- { :name => name, :href => href }
+ if node.name == 'h2'
+ { :name => name, :href => href }
+ else
+ nil
+ end
end
+ @links.compact!
@readme.css('pre').each do |pre|
# Retrieve language from comment
+ highlight = nil
language = nil
comment = pre.previous.previous
if comment && comment.comment?
- language = comment.content.strip.split('language:')[1]
+ highlight = comment.content.match(/highlight:(\S+)/)
+ language = comment.content.match(/language:(\S+)/)
+ highlight = highlight[1].split(',') if highlight
+ language = language[1] if language
end
+ highlight ||= []
language ||= :ruby
# Insert <pre> tags before the previous element (because its floated right)
@@ -37,7 +47,15 @@
pre.add_previous_sibling('<div class="clear"></div>')
# Pygmentize
- pre.replace Albino.colorize(pre.css('code').text, language)
+ pygmented = Albino.colorize(pre.css('code').text, language)
+
+ # Highlight
+ highlight.each do |str|
+ pygmented = pygmented.gsub(str, '<span class="sr">' + str + '</span>')
+ end
+
+ # Replace <pre>
+ pre.replace pygmented
end
# Insert <div class="clear"> before each <h3> tag
View
3 site/index.html.haml
@@ -16,4 +16,5 @@
#tm Static Sites Made Powerful
#body
~ @readme
- .clear
+ .clear
+ %script{ :src => "jquery-1.6.2.js", :type => "text/javascript" }
View
8,982 site/jquery-1.6.2.js
8,982 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
14 site/stasis.css.scss
@@ -77,19 +77,23 @@ ul {
margin: 20px auto 0;
width: 800px;
+ a {
+ color: #3393E4;
+ }
+
h2 {
border-bottom: 2px solid #434445;
clear: both;
font-size: 19.4px;
padding: 20px 0 5px;
-
- a {
- color: #3393E4;
- }
}
h3 {
font-size: 18px;
+
+ a {
+ color: #CDA869;
+ }
}
p {
@@ -149,7 +153,7 @@ ul {
.gh { color: #000080; font-weight: bold } /* Generic.Heading */
.gi { background: #253B22 } /* Generic.Inserted */
.go { } /* Generic.Output */
- .gp { font-weight: bold; color: #CF6A4C } /* Generic.Prompt */
+ .gp { font-weight: bold; color: #CDA869 } /* Generic.Prompt */
.gs { font-weight: bold } /* Generic.Strong */
.gu { color: #800080; font-weight: bold } /* Generic.Subheading */
.gt { } /* Generic.Traceback */

0 comments on commit a880da8

Please sign in to comment.
Something went wrong with that request. Please try again.