Skip to content

Commit

Permalink
Switch to JS highlighter
Browse files Browse the repository at this point in the history
  • Loading branch information
tdreyno committed Jul 9, 2012
1 parent 671f04a commit 6881316
Show file tree
Hide file tree
Showing 27 changed files with 103 additions and 202 deletions.
4 changes: 1 addition & 3 deletions Gemfile
Expand Up @@ -2,6 +2,4 @@ source :rubygems

gem "redcarpet"
gem "builder"
gem "middleman", "3.0.0.rc.4"
gem "rack-codehighlighter", :git => "git://github.com/wbzyl/rack-codehighlighter.git"
gem "pygments.rb"
gem "middleman", "3.0.0"
8 changes: 0 additions & 8 deletions config.rb
Expand Up @@ -5,14 +5,6 @@
set :markdown, :tables => true, :autolink => true
set :markdown_engine, :redcarpet

require 'rack/codehighlighter'
require "pygments"
use Rack::Codehighlighter,
:pygments,
:element => "pre>code",
:pattern => /\A:::([-_+\w]+)\s*\n/,
:markdown => true

# Build-specific configuration
configure :build do
# For example, change the Compass output style for deployment
Expand Down
4 changes: 2 additions & 2 deletions helpers/guide_helpers.rb
Expand Up @@ -23,8 +23,8 @@ def pages_for_group(group_name)
return pages unless group

if group.directory
pages << sitemap.resources.select { |r|
r.path.include? group.directory
pages << sitemap.resources.select { |r|
r.path.include?(group.directory) && !r.data.hidden
}.map do |r|
::Middleman::Util.recursively_enhance({
:title => r.data.title,
Expand Down
2 changes: 1 addition & 1 deletion source/.htaccess
Expand Up @@ -6,12 +6,12 @@ RewriteRule ^guides/frontend-optimization/?$ /advanced/frontend-optimization [R=
RewriteRule ^guides/pretty-urls/?$ /advanced/pretty-urls [R=301,L]
RewriteRule ^guides/rack-middleware/?$ /advanced/rack-middleware [R=301,L]
RewriteRule ^guides/speeding-up/?$ /advanced/speeding-up [R=301,L]
RewriteRule ^guides/localization/?$ /advanced/localization [R=301,L]

# Extensions
RewriteRule ^guides/blog/?$ /extensions/blog [R=301,L]
RewriteRule ^guides/extensions/?$ /extensions/custom [R=301,L]
RewriteRule ^guides/livereload/?$ /extensions/livereload [R=301,L]
RewriteRule ^guides/localization/?$ /extensions/localization [R=301,L]
RewriteRule ^guides/remote-api/?$ /extensions/remote-api [R=301,L]

# Getting Started
Expand Down
2 changes: 0 additions & 2 deletions source/advanced/dynamic-pages.html.markdown
Expand Up @@ -6,7 +6,6 @@ title: Dynamic Pages

Middleman has the ability to generate pages which do not have a one-to-one relationship with their template files. What this means is that you can have a single template which generates multiple files based on variables. Here's an example `config.rb` setup:

:::ruby
["tom", "dick", "harry"].each do |name|
page "/about/#{name}.html", :proxy => "/about/template.html" do
@person_name = name
Expand All @@ -22,7 +21,6 @@ When this project is built, four files will be output:

In most cases, you will not want to generate the template itself without the @person_name variable, so you can tell Middleman to ignore it:

:::ruby
["tom", "dick", "harry"].each do |name|
page "/about/#{name}.html", :proxy => "/about/template.html", :ignore => true do
@person_name = name
Expand Down
7 changes: 0 additions & 7 deletions source/advanced/file-size-optimization.html.markdown
Expand Up @@ -10,7 +10,6 @@ Middleman handles CSS minification and Javascript compression so you don't have

In your `config.rb`, activate the `minify_css` and `minify_javascript` features during the build of your site.

:::ruby
configure :build do
activate :minify_css
activate :minify_javascript
Expand All @@ -20,7 +19,6 @@ If you are already using a compressed file that includes `.min` in its filename,

You can customize how the JavaScript compressor works by setting the `:compressor` option when activating the `:minify_javascript` extension in `config.rb` to a custom instance of Uglifier. See (Uglifier's docs)[https://github.com/lautis/uglifier] for details. For example, you could enable unsafe optimizations and mangle top-level variable names like this:

:::ruby
set :js_compressor, Uglifier.new(:toplevel => true, :unsafe => true)

If you want to exclude any files from being minified, pass the `:ignore` option when activating these extensions, and give it one or more globs, regexes, or procs that identify the files to ignore. Likewise, you can pass an `:exts` option to change which file extensions are renamed.
Expand All @@ -29,7 +27,6 @@ If you want to exclude any files from being minified, pass the `:ignore` option

It's a good idea to [serve compressed files](http://developer.yahoo.com/performance/rules.html#gzip) to user agents that can handle it. Many web servers have the ability to gzip files on the fly, but that requires CPU work every time the file is served, and as a result most servers don't perform the maximum compression. Middleman can produce gripped versions of your HTML, CSS, and JavaScript alongside your regular files, and you can instruct your web server to serve those pre-gzipped files directly. First, enable the `:gzip` extension:

:::ruby
activate :gzip

Then configure your server to serve those files. If you use Nginx, check out [the gzip_static](http://wiki.nginx.org/NginxHttpGzipStaticModule) module. For Apache, you'll have to do something a little trickier - see [this Gist](https://gist.github.com/2200790) for an example.
Expand All @@ -40,17 +37,13 @@ If you also want to compress images on build, you can use the [Middleman Smusher

To install:

:::bash
gem install middleman-smusher

Then activate in your `config.rb`:

:::ruby
configure :build do
activate :smusher
end



[Middleman Smusher extension]: https://github.com/middleman/middleman-smusher
[Yahoo's Smush.it tool]: http://www.smushit.com/ysmush.it/
2 changes: 0 additions & 2 deletions source/advanced/improving-cacheability.html.markdown
Expand Up @@ -10,7 +10,6 @@ To make your website render as quickly as possible, you should serve any assets,

The most effective technique for preventing users from using outdated files is to change the asset's filename every time you change one of your assets. Since that would be a pain to do by hand, Middleman comes with an `:asset_hash` extension that does it for you. First, activate the extension in your `config.rb`:

:::ruby
activate :asset_hash

Now, refer to your assets as normal, with their original filename. You can use helpers like `image_tag` as well. However, when your site is built, each asset will be produced with a bit of extra text at the end of the filename that is tied to the content of the file, and all of your other files (HTML, CSS, JavaScript, etc) will be changed to reference that unique-ified filename instead of the original one. Now you can serve your assets with a "never expire" policy, but be sure that when you change them, they'll show up as a different filename.
Expand All @@ -23,7 +22,6 @@ If you want to exclude any files from being renamed, pass the `:ignore` option w

The second approach is to append a value to the end of URLs that reference your assets. For example, instead of referencing `my_image.png` you'd reference `my_image.png?1234115152`. The extra info at the end of the URL is enough to tell many (but not all) browsers and proxies to cache that file separately from the same file with a different cache buster value. To use this, activate the `:cache_buster` extension in your `config.rb`:

:::ruby
activate :cache_buster

Now, to use cache-safe URLs, you must use [asset path helpers](http://www.padrinorb.com/api/Padrino/Helpers/AssetTagHelpers.html) like `image_path` or `javascript_include_tag`. Make sure to use [Compass helpers](http://compass-style.org/reference/compass/helpers/urls/) in your SASS too (`image-url`, etc.). For JavaScript, you'll need to make ERb templates like `my script.js.erb` and call asset helpers via ERb tags to output the right values. If you forget one, your users will still get the file (since the copy on the server just has a normal name) but they might not see changes.
Expand Down
Expand Up @@ -4,35 +4,26 @@ title: Localization (i18n)

# Localization (i18n)

Middleman 2.1 ships with an official extension to support basic localization which allows you to build pages for multiple languages with a single set of templates. Simply install the gem:
The extension provides an api for enabling localization in your `config.rb`:

:::bash
gem install middleman-i18n

The extension provides a new api for enabling localization in your `config.rb`:

:::ruby
activate :i18n

By default this will search the `locales` folder in the root of your project for YAML files representing each locale you want to support. The YAML file is a set of keys and values for each string you need to localize in your site. The keys, which is how you will refer to these strings in your templates, must be the same in each locale, but the values will change. Here are two example YAML files.

`locales/en.yml`:

:::yaml
---
en:
hello: "Hello"

`locales/es.yml`:

:::yaml
---
es:
hello: "Hola"

Localizable templates live in the `source/localizable` folder by default (see below on how to change this option). Each template in that folder will have access to the `I18n` helper. Using this helper, you can refer to keys from your YAML files and inject the language-specific values into your template. Here's a simple `source/localizable/hello_world.html.erb` template:

:::erb
<%= I18n.t(:hello) %> World

This would output two files:
Expand All @@ -50,7 +41,6 @@ Each individual language is accessible in its own namespaced path. By default, t

You can change this with the `:path` option, but remember: the URL will always include the name of the YAML file:

:::ruby
activate :i18n, :path => "/langs/:locale/"

Now the paths would be:
Expand All @@ -61,7 +51,6 @@ Now the paths would be:

If you are unhappy using the YAML file names as part of your path, you can remap them to different values.

:::ruby
activate :i18n, :path => "/langs/:locale/",
:lang_map => { :en => :english, :es => :spanish, :fr => :french }

Expand All @@ -82,7 +71,6 @@ Let's say we have a file `source/localizable/hello.html.erb`. By default, this w

If we want to rename that file to `hola.html` for Spanish only, we can use the `paths` key in `locales/es.yml`:

:::yaml
---
es:
hello: "Hola"
Expand All @@ -98,15 +86,13 @@ Now, the files would be output as:

By default, the contents of `source/localizable` will be built in multiple languages while the rest of your templates will continue to work normally. The name of this folder can be changed with the `:templates_dir` option:

:::ruby
# Look in `source/language_specific` instead
activate :i18n, :templates_dir => "language_specific"

## Manually specifying languages

If you'd prefer specify a list of supported languages rather than automatically discovering files in `locales/`, you can use the `:langs` option:

:::ruby
activate :i18n, :langs => [:en] # Ignore all languages except :en

## Default (Root) Language
Expand All @@ -119,7 +105,6 @@ By default, the first language (either specified by `:langs` or discovered in yo

You can change the default or disable mounting a specific language at the root entirely using the `:mount_at_root` option:

:::ruby
activate :i18n, :mount_at_root => :es # Mount spanish at root instead
# or
activate :i18n, :mount_at_root => false # All languages will be prefixed
5 changes: 0 additions & 5 deletions source/advanced/pretty-urls.html.markdown
Expand Up @@ -14,7 +14,6 @@ This makes sense for a static website, but many find the .html distasteful and w

If you are using a Rack-based web-server, you can use the `Rack::TryStatic` middleware found in the [rack-contrib] project. In your `config.ru` (or Rails Rack configuration), add the following:

:::ruby
require "rack/contrib/try_static"
use Rack::TryStatic, :root => "build", :urls => %w[/], :try => ['.html']

Expand All @@ -28,7 +27,6 @@ However, serving your site via Rack somewhat defeats the purpose of generating a

If you are not using a Rack-based web-server, you can use the Directory Indexes feature to tell Middleman to create a folder for each `.html` file and place the built template file as the index of that folder. In your `config.rb`:

:::ruby
activate :directory_indexes

Now when the above project is built, the `about-us.html.erb` file will be output as `about-us/index.html`. When placed in an Apache compatible web-server, the page would be available at:
Expand All @@ -37,19 +35,16 @@ Now when the above project is built, the `about-us.html.erb` file will be output

If you prefer a different file be output, you can use the `index_file` variable. For example, IIS uses default.html:

:::ruby
set :index_file, "default.html"

Or, you may want a PHP file:

:::ruby
set :index_file, "index.php"

### Opt-out

If there are pages which you don't want automatically renamed, you can opt-out:

:::ruby
page "/i-really-want-the-extension.html", :directory_index => false

`page` works with regexes or file globs if you want to turn off indexes for many files at once.
Expand Down
2 changes: 0 additions & 2 deletions source/advanced/rack-middleware.html.markdown
Expand Up @@ -12,7 +12,6 @@ Middleman has full access to Rack Middleware which opens up an expansive univers

This site is written in Middleman and features many code blocks which have syntax highlighting. This syntax highlighting is accomplished outside the scope of Middleman. This site renders `<code>` blocks and then Rack Middleware takes over an enhances those blocks with syntax highlight. The middleware in use is called [`Rack::Codehighlighter`](https://github.com/wbzyl/rack-codehighlighter). Here's how it can be used in your `config.rb`:

:::ruby
require 'rack/codehighlighter'
require "pygments"
use Rack::Codehighlighter,
Expand All @@ -23,7 +22,6 @@ This site is written in Middleman and features many code blocks which have synta

Make sure you add the right dependencies to your `Gemfile` to make those work:

:::ruby
gem "rack-codehighlighter", :git => "git://github.com/wbzyl/rack-codehighlighter.git"
gem "pygments.rb"

Expand Down
2 changes: 0 additions & 2 deletions source/advanced/speeding-up.html.markdown
Expand Up @@ -14,7 +14,6 @@ The latest version of Ruby, version 1.9.3, is much faster than its predecessor.

Use `therubyracer` which uses the Google Chrome engine to compile Javascript. Using a faster JSON parser can also speed up Javascript minification. In your Gemfile:

:::ruby
gem 'therubyracer' # faster ExecJS
gem 'oj' # faster JSON
# gem 'yajl-ruby' # if 'oj' doesn't work for you
Expand All @@ -25,7 +24,6 @@ Don't forget to run `bundle install`!

Middleman includes `maruku` for rendering Markdown by default, but you can use the `redcarpet` gem for a speed boost (and some nice features):

:::ruby
# in Gemfile
gem 'redcarpet' # faster ExecJS

Expand Down
13 changes: 0 additions & 13 deletions source/extensions/blog.html.markdown
Expand Up @@ -6,24 +6,20 @@ title: Blogging Extension

Middleman has an official extension to support blogging, articles and tagging. `middleman-blog` ships as an extension and must be installed to use. Simply specify the gem in your `Gemfile`:

:::ruby
gem "middleman-blog"

Or install it by hand if you're not using Bundler:

:::bash
gem install middleman-blog

Then activate the extension in your `config.rb`:

:::ruby
activate :blog do |blog|
# set options on blog
end

Alternatively, you can generate a fresh project already setup for blogging:

:::bash
middleman init MY_BLOG_PROJECT --template=blog

If you already have a Middleman project, you can re-run `middleman init` with the blog template option to generate the sample [`index.html`](https://github.com/middleman/middleman-blog/blob/master/lib/middleman-blog/template/source/index.html.erb), [`tag.html`](https://github.com/middleman/middleman-blog/blob/master/lib/middleman-blog/template/source/tag.html.erb), [`calendar.html`](https://github.com/middleman/middleman-blog/blob/master/lib/middleman-blog/template/source/calendar.html.erb), and [`feed.xml`](https://github.com/middleman/middleman-blog/blob/master/lib/middleman-blog/template/source/feed.xml.builder), or you can write those yourself. You can see [what gets generated](https://github.com/middleman/middleman-blog/tree/master/lib/middleman-blog/template/source) on GitHub.
Expand All @@ -48,14 +44,12 @@ As a shortcut, you can run `middleman article TITLE` and Middleman will create a

The base path for your blog defaults to `/` (the root of your website) but can be overridden in `config.rb`:

:::ruby
activate :blog do |blog|
# set options on blog
end

The permalink for viewing your posts can be easily changed as well:

:::ruby
activate :blog do |blog|
blog.permalink = "blog/:year/:title.html"
end
Expand All @@ -68,7 +62,6 @@ By default, articles can be truncated when viewed outside their permalink page.

This can be changed in `config.rb`:

:::ruby
activate :blog do |blog|
blog.summary_separator = /SPLIT_SUMMARY_BEFORE_THIS/
end
Expand All @@ -93,7 +86,6 @@ Now you can find this article listed on `tags/blogging.html`.

This path can be changed in `config.rb`:

:::ruby
activate :blog do |blog|
blog.taglink = "categories/:tag.html"
end
Expand All @@ -112,7 +104,6 @@ In templates, you can use the [`blog_year_path`](http://rubydoc.info/github/midd

You can set a specific [layout](/templates/templates-layouts-partials) to be used for all articles in your `config.rb`:

:::ruby
activate :blog do |blog|
blog.layout = "blog_layout"
end
Expand All @@ -127,7 +118,6 @@ Each [`BlogArticle`](http://rubydoc.info/github/middleman/middleman-blog/master/

For example, the following shows the 5 most-recent articles and their summary:

:::erb
<% blog.articles[0...5].each do |article| %>
<article>
<h1>
Expand All @@ -143,7 +133,6 @@ For example, the following shows the 5 most-recent articles and their summary:

You can also get access to the tag data for a tag archive:

:::erb
<ul>
<% blog.tags.each do |tag, articles| %>
<li>
Expand All @@ -158,7 +147,6 @@ You can also get access to the tag data for a tag archive:

Or similarly for a calendar list:

:::erb
<ul>
<% blog.articles.group_by {|a| a.date.year }.each do |year, articles| %>
<li>
Expand All @@ -174,7 +162,6 @@ Or similarly for a calendar list:

Or if you added a `published` flag to your front matter:

:::erb
<h1>Published Articles</h1>
<% blog.articles.select {|a| a.page.data[:published] }.each do |article| %>
...
Expand Down

0 comments on commit 6881316

Please sign in to comment.