-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME
More file actions
126 lines (93 loc) · 3.25 KB
/
README
File metadata and controls
126 lines (93 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
Introduction
============
Tidy gives you an easy way to organize/manage your CSS and Javascript files
via two helper methods in the ApplicationHelpers module:
tidy_javascripts
tidy_stylesheets
Place your stylesheets and script files in pre-defined sub-directories under
your app's public/, and Tidy figures out which ones to load.
Usage
=====
First, install the plugin using this command:
script/plugin install http://github.com/bitaxis/tidy.git
Next, invoke either or both methods in your layout(s). For instance,
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<title>My Rails App</title>
<%= stylesheet_link_tag tidy_stylesheets %>
<%= javascript_include_tag tidy_javascripts %>
</head>
<body>
<%= yield %>
</body>
</html>
Then, author your code, taking care to place CSS and Javascript files in the
following sub-directories:
public/javascripts
public/stylesheets
How It Works
============
For Javascripts, Tidy includes these Javascript files in the following order,
skipping non-existent ones:
1. public/javascripts/application.js
2. public/javascripts/<controller-name>/_controller.js
3. public/javascripts/<template-path>.js
4. public/javascript/<partial-path(s)>.js
For stylesheets, Tidy includes these stylesheets in the following order,
skipping non-existent ones:
1. public/stylesheets/application.css
2. public/stylesheets/<controller-name>/_controller.css
3. public/stylesheets/<template-path>.css
4. public/stylesheets/<partial-path(s)>.css
Example
=======
Suppose your Rails application resembles the following:
my_rails_app/
app/
controllers/
projects_controller.rb
views/
projects/
edit.html.erb
index.html.erb
new.html.erb
show.html.erb
shared/
_navigation.html.erb
public/
javascripts/
application.js
projects/
_controller.js
index.js
stylesheets/
application.css
projects/
index.css
shared/
_navigation.css
Rendering the projects/index view will cause Tidy to load the following
Javascript files:
1. public/javascripts/application.js
2. public/javascripts/projects/_controller.js
3. public/javascripts/projects/index.js
Similarly, rendering the projects/index view will cause Tidy to load the
following CSS files:
1. public/stylesheets/application.css
2. public/stylesheets/projects/index.css
3. public/stylesheets/shared/_navigation.css
Tidy won't try to load public/stylesheets/projects/_controller.css because it
does not exist.
Low Pro
=======
Tidy works great with Dan Webb's Low Pro for unobtrusive Javascripting. If
you are not yet a fan, check it out at http://github.com/danwrong/low-pro/.
Credits
=======
Tidy was originally inspired by Peter Harkin's blog post at
http://push.cx/2006/tidy-stylesheets-in-rails. I first expanded his idea to
also manage Javascripts. It is now available as a plugin.
Copyright (c) bitaxis.com, released under the MIT license.