Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fix code highlight in README

  • Loading branch information...
commit 84e7df78622aeeef3b06f2ef20f297d17568e1b6 1 parent 9bc00a3
Sasha Koss authored December 10, 2012

Showing 1 changed file with 139 additions and 107 deletions. Show diff stats Hide diff stats

  1. 246  README.md
246  README.md
Source Rendered
@@ -16,15 +16,19 @@ Nestive is *better* because it addresses these problems.
16 16
 
17 17
 The `area` helper is a lot like Rails' own `<%= yield :foo %>`, and is used in layouts to define and render a chunk of content in your layout:
18 18
 
19  
-    <%= area :sidebar %>
  19
+``` erb
  20
+<%= area :sidebar %>
  21
+```
20 22
 
21 23
 Unlike `yield`, `area` will allow your parent layouts to add content to the area at the same time using either a String or a block:
22 24
 
23  
-    <%= area :sidebar, "Some Content Here" %>
  25
+``` erb
  26
+<%= area :sidebar, "Some Content Here" %>
24 27
 
25  
-    <%= area :sidebar do %>
26  
-      Some Content Here
27  
-    <% end %>
  28
+<%= area :sidebar do %>
  29
+  Some Content Here
  30
+<% end %>
  31
+```
28 32
 
29 33
 It's important to note that this isn't *default* content, it *is* the content (unless a child changes it).
30 34
 
@@ -32,147 +36,175 @@ It's important to note that this isn't *default* content, it *is* the content (u
32 36
 
33 37
 The implementation details are quite different, but the `append` helper works much like Rails' built-in `content_for`. It will work with either a String or block, adding the new content onto the end of any content previously provided by parent layouts:
34 38
 
35  
-    <%= extends :application do %>
36  
-      <% append :sidebar, "More content." %>
37  
-      <% append :sidebar do %>
38  
-        More content.
39  
-      <% end %>
40  
-    <% end %>
  39
+``` erb
  40
+<%= extends :application do %>
  41
+  <% append :sidebar, "More content." %>
  42
+  <% append :sidebar do %>
  43
+    More content.
  44
+  <% end %>
  45
+<% end %>
  46
+```
41 47
 
42 48
 ### Prepending content to an area:
43 49
 
44 50
 Exactly what you think it is. The reverse of `append` (duh), adding the new content at the start of any content previously provided by parent layouts:
45 51
 
46  
-    <%= extends :application do %>
47  
-      <%= prepend :sidebar, "Content." %>
48  
-      <%= prepend :sidebar do %>
49  
-        Content.
50  
-      <% end %>
51  
-    <% end %>
  52
+``` erb
  53
+<%= extends :application do %>
  54
+  <%= prepend :sidebar, "Content." %>
  55
+  <%= prepend :sidebar do %>
  56
+    Content.
  57
+  <% end %>
  58
+<% end %>
  59
+```
52 60
 
53 61
 ### Replacing content
54 62
 
55 63
 You can also replace any content provided by parent layouts:
56 64
 
57  
-    <%= extends :application do %>
58  
-      <%= replace :sidebar, "New content." %>
59  
-      <%= replace :sidebar do %>
60  
-        New content.
61  
-      <% end %>
62  
-    <% end %>
  65
+``` erb
  66
+<%= extends :application do %>
  67
+  <%= replace :sidebar, "New content." %>
  68
+  <%= replace :sidebar do %>
  69
+    New content.
  70
+  <% end %>
  71
+<% end %>
  72
+```
63 73
 
64 74
 ### Extending a layout in a child layout (or view):
65 75
 
66 76
 Any layout (or view) can declare that it wants to inherit from and extend a parent layout, in this case we're extending `app/views/layouts/application.html.erb`:
67 77
 
68  
-    <%= extends :application do %>
69  
-       ...
70  
-    <% end %>
  78
+``` erb
  79
+<%= extends :application do %>
  80
+   ...
  81
+<% end %>
  82
+```
71 83
 
72 84
 You can nest many levels deep:
73 85
 
74  
-    # app/views/layouts/application.html.erb
75  
-    <!DOCTYPE html>
76  
-      <html>
77  
-        <head>
78  
-          <%= area :head do %>
79  
-            <title><%= area :title, 'Nestive' %></title>
80  
-          <% end %>
81  
-        </head>
82  
-      <body>
83  
-        <%= yield %>
84  
-      </body>
85  
-    </html>
86  
-
87  
-    # app/views/layouts/with_sidebar.html.erb
88  
-    <%= extends :application do %>
89  
-      <div class="sidebar"><%= area(:sidebar) do %>
90  
-        here goes sidebar
91  
-      <% end %></div>
92  
-      <%= yield -%>
93  
-    <% end %>
94  
-
95  
-    # app/views/layouts/blog_posts.html.erb
96  
-    <%= extends :with_sidebar do %>
97  
-      <% append :sidebar do %>
98  
-        Blog archive:
99  
-        <%= render_blog_archive %>
100  
-      <% end %>
  86
+`app/views/layouts/application.html.erb`:
101 87
 
102  
-      <% append :head do %>
103  
-        <%= javascript_include_tag 'fancy_blog_archive_tag_cloud' %>
  88
+``` erb
  89
+<!DOCTYPE html>
  90
+  <html>
  91
+    <head>
  92
+      <%= area :head do %>
  93
+        <title><%= area :title, 'Nestive' %></title>
104 94
       <% end %>
105  
-
106  
-      <%= yield %>
107  
-    <% end %>
108  
-
109  
-
  95
+    </head>
  96
+  <body>
  97
+    <%= yield %>
  98
+  </body>
  99
+</html>
  100
+```
  101
+
  102
+`app/views/layouts/with_sidebar.html.erb`:
  103
+
  104
+``` erb
  105
+<%= extends :application do %>
  106
+  <div class="sidebar"><%= area(:sidebar) do %>
  107
+    here goes sidebar
  108
+  <% end %></div>
  109
+  <%= yield -%>
  110
+<% end %>
  111
+```
  112
+
  113
+`app/views/layouts/blog_posts.html.erb`:
  114
+
  115
+``` erb
  116
+<%= extends :with_sidebar do %>
  117
+  <% append :sidebar do %>
  118
+    Blog archive:
  119
+    <%= render_blog_archive %>
  120
+  <% end %>
  121
+
  122
+  <% append :head do %>
  123
+    <%= javascript_include_tag 'fancy_blog_archive_tag_cloud' %>
  124
+  <% end %>
  125
+
  126
+  <%= yield %>
  127
+<% end %>
  128
+```
110 129
 
111 130
 ## The token blog example
112 131
 
113 132
 Set-up a global layout defining some content areas.
114 133
 
115  
-    # app/views/layouts/application.html.erb
116  
-    <!DOCTYPE html>
117  
-    <html>
118  
-    <head>
119  
-      <meta charset="utf-8">
120  
-      <title><%= area :title, "JustinFrench.com" %></title>
121  
-      <meta name="description" content="<%= area :description, "This is my website." %>">
122  
-      <meta name="keywords" content="<%= area :keywords, "justin, french, ruby, design" %>">
123  
-    </head>
124  
-    <body>
125  
-      <div id="wrapper">
126  
-        <div id="content">
127  
-          <%= area :content do %>
128  
-            <p>Default content goes here.</p>
129  
-          <% end %>
130  
-        </div>
131  
-        <div id="sidebar">
132  
-          <%= area :sidebar do %>
133  
-            <h2>About Me</h2>
134  
-            <p>...</p>
135  
-          <% end %>
136  
-        </div>
137  
-      </div>
138  
-      <%= yield %>
139  
-    </body>
140  
-    </html>
  134
+`app/views/layouts/application.html.erb`:
  135
+
  136
+``` erb
  137
+<!DOCTYPE html>
  138
+<html>
  139
+<head>
  140
+  <meta charset="utf-8">
  141
+  <title><%= area :title, "JustinFrench.com" %></title>
  142
+  <meta name="description" content="<%= area :description, "This is my website." %>">
  143
+  <meta name="keywords" content="<%= area :keywords, "justin, french, ruby, design" %>">
  144
+</head>
  145
+<body>
  146
+  <div id="wrapper">
  147
+    <div id="content">
  148
+      <%= area :content do %>
  149
+        <p>Default content goes here.</p>
  150
+      <% end %>
  151
+    </div>
  152
+    <div id="sidebar">
  153
+      <%= area :sidebar do %>
  154
+        <h2>About Me</h2>
  155
+        <p>...</p>
  156
+      <% end %>
  157
+    </div>
  158
+  </div>
  159
+  <%= yield %>
  160
+</body>
  161
+</html>
  162
+```
141 163
 
142 164
 Next, we set-up a `blog` layout that extends `application`, replacing, appending & prepending content to the areas we defined earlier.
143 165
 
144  
-    # app/views/layouts/blog.html.erb
145  
-    <%= extends :application do %>
146  
-      <% replace :title, "My Blog – " %>
147  
-      <% replace :description, "Justin French blogs here on Ruby, Rails, Design, Formtastic, etc" %>
148  
-      <% prepend :keywords, "blog, weblog, design links, ruby links, formtastic release notes, " %>
149  
-      <%= yield %>
150  
-    <% end %>
  166
+`app/views/layouts/blog.html.erb`:
  167
+
  168
+``` erb
  169
+<%= extends :application do %>
  170
+  <% replace :title, "My Blog – " %>
  171
+  <% replace :description, "Justin French blogs here on Ruby, Rails, Design, Formtastic, etc" %>
  172
+  <% prepend :keywords, "blog, weblog, design links, ruby links, formtastic release notes, " %>
  173
+  <%= yield %>
  174
+<% end %>
  175
+```
151 176
 
152 177
 Now in our blog index view we can use `blog` layout and fill in the areas with content specific to the index action.
153 178
 
154  
-    # app/views/posts/index.html.erb
155  
-    <% replace :content do %>
156  
-      <h1>My Blog</h1>
157  
-      <%= render @articles %>
158  
-    <% end %>
159 179
 
160  
-    <% append :sidebar do %>
161  
-      <h2>Blog Roll</h2>
162  
-      <%= render @links %>
163  
-    <% end %>
  180
+`app/views/posts/index.html.erb`:
  181
+
  182
+``` erb
  183
+<% replace :content do %>
  184
+  <h1>My Blog</h1>
  185
+  <%= render @articles %>
  186
+<% end %>
  187
+
  188
+<% append :sidebar do %>
  189
+  <h2>Blog Roll</h2>
  190
+  <%= render @links %>
  191
+<% end %>
  192
+```
164 193
 
165 194
 We also need to instruct the `PostsController` to use this `blog` layout:
166 195
 
167  
-    # app/controllers/posts_controller.rb
168  
-    class PostsController < ApplicationController
169  
-      layout 'blog'
170  
-    end
  196
+`app/controllers/posts_controller.rb`:
  197
+
  198
+``` ruby
  199
+class PostsController < ApplicationController
  200
+  layout 'blog'
  201
+end
  202
+```
171 203
 
172 204
 
173 205
 ## Installation
174 206
 
175  
-* add `gem 'nestive', '~> 0.2'` to your gemfile
  207
+* add `gem 'nestive', '~> 0.2'` to your Gemfile
176 208
 * run `bundle`
177 209
 
178 210
 ## Compatibility

0 notes on commit 84e7df7

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