-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add snippet to convert rails 2.3 views to 3.0
- Loading branch information
Showing
3 changed files
with
76 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
Synvert::Rewriter.new 'convert_views_2_3_to_3_0' do | ||
description <<-EOF | ||
1. remove h helper, rails 3 uses it by default. | ||
<%= h user.login %> => <%= user.login %> | ||
2. use erb expression instead of erb statement for view helpers. | ||
<% form_for post do |f| %> | ||
<% end %> | ||
=> | ||
<%= form_for post do |f| %> | ||
<% end %> | ||
EOF | ||
|
||
%w(app/views/**/*.html.erb app/helpers/**/*.rb).each do |file_pattern| | ||
# <%= h user.login %> => <%= user.login %> | ||
within_files file_pattern do | ||
with_node type: 'send', receiver: nil, message: 'h' do | ||
replace_with "{{arguments}}" | ||
end | ||
end | ||
|
||
%w(form_for form_tag).each do |message| | ||
# <% form_for post do |f| %> | ||
# <% end %> | ||
# => | ||
# <%= form_for post do |f| %> | ||
# <% end %> | ||
within_files file_pattern do | ||
with_node type: 'block', caller: {type: 'send', receiver: nil, message: message} do | ||
replace_erb_stmt_with_expr | ||
end | ||
end | ||
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,38 @@ | ||
# encoding: utf-8 | ||
|
||
require 'spec_helper' | ||
|
||
describe 'Convert rails views from 2.3 to 3.0' do | ||
before do | ||
rewriter_path = File.join(File.dirname(__FILE__), '../../lib/rails/convert_views_2_3_to_3_0.rb') | ||
@rewriter = eval(File.read(rewriter_path)) | ||
end | ||
|
||
describe 'with fakefs', fakefs: true do | ||
let(:posts_show_content) {""" | ||
<%= h user.login %> | ||
<%= post.title %> | ||
<% form_for post, :html => {:id => 'post-form'} do |f| %> | ||
<% end %> | ||
<%= form_for post do |f| %> | ||
<% end %> | ||
"""} | ||
let(:posts_show_rewritten_content) {""" | ||
<%= user.login %> | ||
<%= post.title %> | ||
<%= form_for post, :html => {:id => 'post-form'} do |f| %> | ||
<% end %> | ||
<%= form_for post do |f| %> | ||
<% end %> | ||
"""} | ||
|
||
it 'converts' do | ||
FileUtils.mkdir_p 'app/views/posts' | ||
File.write 'app/views/posts/show.html.erb', posts_show_content | ||
@rewriter.process | ||
expect(File.read 'app/views/posts/show.html.erb').to eq posts_show_rewritten_content | ||
end | ||
end | ||
end |