Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
lifo
committed
Apr 17, 2009
1 parent
abb899c
commit 5b92dcb
Showing
10 changed files
with
121 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,31 @@ | ||
module Levenshtein | ||
# Based on the pseudocode in http://en.wikipedia.org/wiki/Levenshtein_distance. | ||
def self.distance(s1, s2) | ||
s = s1.unpack('U*') | ||
t = s2.unpack('U*') | ||
m = s.length | ||
n = t.length | ||
module RailsGuides | ||
module Levenshtein | ||
# Based on the pseudocode in http://en.wikipedia.org/wiki/Levenshtein_distance. | ||
def self.distance(s1, s2) | ||
s = s1.unpack('U*') | ||
t = s2.unpack('U*') | ||
m = s.length | ||
n = t.length | ||
|
||
# matrix initialization | ||
d = [] | ||
0.upto(m) { |i| d << [i] } | ||
0.upto(n) { |j| d[0][j] = j } | ||
# matrix initialization | ||
d = [] | ||
0.upto(m) { |i| d << [i] } | ||
0.upto(n) { |j| d[0][j] = j } | ||
|
||
# distance computation | ||
1.upto(m) do |i| | ||
1.upto(n) do |j| | ||
cost = s[i] == t[j] ? 0 : 1 | ||
d[i][j] = [ | ||
d[i-1][j] + 1, # deletion | ||
d[i][j-1] + 1, # insertion | ||
d[i-1][j-1] + cost, # substitution | ||
].min | ||
# distance computation | ||
1.upto(m) do |i| | ||
1.upto(n) do |j| | ||
cost = s[i] == t[j] ? 0 : 1 | ||
d[i][j] = [ | ||
d[i-1][j] + 1, # deletion | ||
d[i][j-1] + 1, # insertion | ||
d[i-1][j-1] + cost, # substitution | ||
].min | ||
end | ||
end | ||
end | ||
|
||
# all done | ||
return d[m][n] | ||
# all done | ||
return d[m][n] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
h2. Action View Overview | ||
|
||
In this guide you will learn: | ||
|
||
* What Action View is, and how to use it | ||
|
||
endprologue. | ||
|
||
h3. What is Action View? | ||
|
||
TODO... | ||
|
||
h3. Using Action View with Rails | ||
|
||
TODO... | ||
|
||
h3. Using Action View outside of Rails | ||
|
||
TODO... | ||
|
||
h3. Templates, Partials and Layouts | ||
|
||
TODO... | ||
|
||
h3. Using Templates, Partials and Layouts in "The Rails Way" | ||
|
||
TODO... | ||
|
||
h3. Partial Layouts | ||
|
||
TODO... | ||
|
||
h3. View Paths | ||
|
||
TODO... | ||
|
||
h3. Overview of all the helpers provided by AV | ||
|
||
TODO... | ||
|
||
h3. Localized Views | ||
|
||
Action View has the ability render different templates depending on the current locale. | ||
|
||
For example, suppose you have a Posts controller with a show action. By default, calling this action will render +app/views/posts/show.html.erb+. But if you set +I18n.locale = :de+, then +app/views/posts/show.de.html.erb+ will be rendered instead. If the localized template isn't present, the undecorated version will be used. This means you're not required to provide localized views for all cases, but they will be preferred and used if available. | ||
|
||
TODO add full code example... | ||
|
||
You can use the same technique to localize the rescue files in your public directory. For example, setting +I18n.locale = :de+ and creating +public/500.de.html+ and +public/404.de.html+ would allow you to have localized rescue pages. | ||
|
||
Since Rails doesn't restrict the symbols that you use to set I18n.locale, you can leverage this system to display different content depending on anything you like. For example, suppose you have some "expert" users that should see different pages from "normal" users. You could add the following to +app/controllers/application.rb+: | ||
|
||
<ruby> | ||
before_filter :set_expert_locale | ||
|
||
def set_expert_locale | ||
I18n.locale = :expert if current_user.expert? | ||
end | ||
</ruby> | ||
|
||
Then you could create special views like +app/views/posts/show.expert.html.erb+, which would only be displayed to expert users. | ||
|
||
You can read more about the Rails Internationalization (I18n) API "here":i18n.html. | ||
|
||
h3. Changelog | ||
|
||
"Lighthouse Ticket":http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/71 | ||
|
||
* April 5, 2009: Starting work by Trevor Turk, leveraging Mike Gunderloy's docs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
railties/guides/source/rails_application_templates.textile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
h2. Rails Application Templates | ||
|
||
This guide covers the Rails application templates, By referring to this guide, you will be able to: | ||
|
||
* Use existing templates to generate a customized Rails application | ||
* Write your own reusable Rails application templates | ||
|
||
endprologue. | ||
|
||
h3. Introduction | ||
|
||
Application templates are simple ruby files containing DSL for adding plugins/gems/initializers etc. to your freshly created Rails project or an existing Rails project. | ||
|
||
h3. Changelog | ||
|
||
"Lighthouse ticket":http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/78 | ||
|
||
* April 17, 2009: Initial version by "Pratik":credits.html#lifo |