Revision 1298:4f746d8966dd .svn/pristine/12
| .svn/pristine/12/120840d537ad68f417065b102e2763e8f985fe62.svn-base | ||
|---|---|---|
| 1 |
# Redmine - project management software |
|
| 2 |
# Copyright (C) 2006-2013 Jean-Philippe Lang |
|
| 3 |
# |
|
| 4 |
# This program is free software; you can redistribute it and/or |
|
| 5 |
# modify it under the terms of the GNU General Public License |
|
| 6 |
# as published by the Free Software Foundation; either version 2 |
|
| 7 |
# of the License, or (at your option) any later version. |
|
| 8 |
# |
|
| 9 |
# This program is distributed in the hope that it will be useful, |
|
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 12 |
# GNU General Public License for more details. |
|
| 13 |
# |
|
| 14 |
# You should have received a copy of the GNU General Public License |
|
| 15 |
# along with this program; if not, write to the Free Software |
|
| 16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
| 17 |
|
|
| 18 |
class MembersController < ApplicationController |
|
| 19 |
model_object Member |
|
| 20 |
before_filter :find_model_object, :except => [:index, :create, :autocomplete] |
|
| 21 |
before_filter :find_project_from_association, :except => [:index, :create, :autocomplete] |
|
| 22 |
before_filter :find_project_by_project_id, :only => [:index, :create, :autocomplete] |
|
| 23 |
before_filter :authorize |
|
| 24 |
accept_api_auth :index, :show, :create, :update, :destroy |
|
| 25 |
|
|
| 26 |
def index |
|
| 27 |
@offset, @limit = api_offset_and_limit |
|
| 28 |
@member_count = @project.member_principals.count |
|
| 29 |
@member_pages = Paginator.new @member_count, @limit, params['page'] |
|
| 30 |
@offset ||= @member_pages.offset |
|
| 31 |
@members = @project.member_principals.all( |
|
| 32 |
:order => "#{Member.table_name}.id",
|
|
| 33 |
:limit => @limit, |
|
| 34 |
:offset => @offset |
|
| 35 |
) |
|
| 36 |
|
|
| 37 |
respond_to do |format| |
|
| 38 |
format.html { head 406 }
|
|
| 39 |
format.api |
|
| 40 |
end |
|
| 41 |
end |
|
| 42 |
|
|
| 43 |
def show |
|
| 44 |
respond_to do |format| |
|
| 45 |
format.html { head 406 }
|
|
| 46 |
format.api |
|
| 47 |
end |
|
| 48 |
end |
|
| 49 |
|
|
| 50 |
def create |
|
| 51 |
members = [] |
|
| 52 |
if params[:membership] |
|
| 53 |
if params[:membership][:user_ids] |
|
| 54 |
attrs = params[:membership].dup |
|
| 55 |
user_ids = attrs.delete(:user_ids) |
|
| 56 |
user_ids.each do |user_id| |
|
| 57 |
members << Member.new(:role_ids => params[:membership][:role_ids], :user_id => user_id) |
|
| 58 |
end |
|
| 59 |
else |
|
| 60 |
members << Member.new(:role_ids => params[:membership][:role_ids], :user_id => params[:membership][:user_id]) |
|
| 61 |
end |
|
| 62 |
@project.members << members |
|
| 63 |
end |
|
| 64 |
|
|
| 65 |
respond_to do |format| |
|
| 66 |
format.html { redirect_to_settings_in_projects }
|
|
| 67 |
format.js { @members = members }
|
|
| 68 |
format.api {
|
|
| 69 |
@member = members.first |
|
| 70 |
if @member.valid? |
|
| 71 |
render :action => 'show', :status => :created, :location => membership_url(@member) |
|
| 72 |
else |
|
| 73 |
render_validation_errors(@member) |
|
| 74 |
end |
|
| 75 |
} |
|
| 76 |
end |
|
| 77 |
end |
|
| 78 |
|
|
| 79 |
def update |
|
| 80 |
if params[:membership] |
|
| 81 |
@member.role_ids = params[:membership][:role_ids] |
|
| 82 |
end |
|
| 83 |
saved = @member.save |
|
| 84 |
respond_to do |format| |
|
| 85 |
format.html { redirect_to_settings_in_projects }
|
|
| 86 |
format.js |
|
| 87 |
format.api {
|
|
| 88 |
if saved |
|
| 89 |
render_api_ok |
|
| 90 |
else |
|
| 91 |
render_validation_errors(@member) |
|
| 92 |
end |
|
| 93 |
} |
|
| 94 |
end |
|
| 95 |
end |
|
| 96 |
|
|
| 97 |
def destroy |
|
| 98 |
if request.delete? && @member.deletable? |
|
| 99 |
@member.destroy |
|
| 100 |
end |
|
| 101 |
respond_to do |format| |
|
| 102 |
format.html { redirect_to_settings_in_projects }
|
|
| 103 |
format.js |
|
| 104 |
format.api {
|
|
| 105 |
if @member.destroyed? |
|
| 106 |
render_api_ok |
|
| 107 |
else |
|
| 108 |
head :unprocessable_entity |
|
| 109 |
end |
|
| 110 |
} |
|
| 111 |
end |
|
| 112 |
end |
|
| 113 |
|
|
| 114 |
def autocomplete |
|
| 115 |
respond_to do |format| |
|
| 116 |
format.js |
|
| 117 |
end |
|
| 118 |
end |
|
| 119 |
|
|
| 120 |
private |
|
| 121 |
|
|
| 122 |
def redirect_to_settings_in_projects |
|
| 123 |
redirect_to settings_project_path(@project, :tab => 'members') |
|
| 124 |
end |
|
| 125 |
end |
|
| .svn/pristine/12/121eeed4fcb10e023ef41b53336708e73d10e3e6.svn-base | ||
|---|---|---|
| 1 |
<%= form_tag({:action => 'edit', :tab => 'authentication'}) do %>
|
|
| 2 |
|
|
| 3 |
<div class="box tabular settings"> |
|
| 4 |
<p><%= setting_check_box :login_required %></p> |
|
| 5 |
|
|
| 6 |
<p><%= setting_select :autologin, [[l(:label_disabled), 0]] + [1, 7, 30, 365].collect{|days| [l('datetime.distance_in_words.x_days', :count => days), days.to_s]} %></p>
|
|
| 7 |
|
|
| 8 |
<p><%= setting_select :self_registration, [[l(:label_disabled), "0"], |
|
| 9 |
[l(:label_registration_activation_by_email), "1"], |
|
| 10 |
[l(:label_registration_manual_activation), "2"], |
|
| 11 |
[l(:label_registration_automatic_activation), "3"]] %></p> |
|
| 12 |
|
|
| 13 |
<p><%= setting_check_box :unsubscribe %></p> |
|
| 14 |
|
|
| 15 |
<p><%= setting_text_field :password_min_length, :size => 6 %></p> |
|
| 16 |
|
|
| 17 |
<p><%= setting_check_box :lost_password, :label => :label_password_lost %></p> |
|
| 18 |
|
|
| 19 |
<p><%= setting_check_box :openid, :disabled => !Object.const_defined?(:OpenID) %></p> |
|
| 20 |
|
|
| 21 |
<p><%= setting_check_box :rest_api_enabled %></p> |
|
| 22 |
|
|
| 23 |
<p><%= setting_check_box :jsonp_enabled %></p> |
|
| 24 |
</div> |
|
| 25 |
|
|
| 26 |
<fieldset class="box"> |
|
| 27 |
<legend><%= l(:label_session_expiration) %></legend> |
|
| 28 |
|
|
| 29 |
<div class="tabular settings"> |
|
| 30 |
<p><%= setting_select :session_lifetime, [[l(:label_disabled), 0]] + [1, 7, 30, 60, 365].collect{|days| [l('datetime.distance_in_words.x_days', :count => days), (days * 60 * 24).to_s]} %></p>
|
|
| 31 |
<p><%= setting_select :session_timeout, [[l(:label_disabled), 0]] + [1, 2, 4, 8, 12, 24, 48].collect{|hours| [l('datetime.distance_in_words.x_hours', :count => hours), (hours * 60).to_s]} %></p>
|
|
| 32 |
</div> |
|
| 33 |
|
|
| 34 |
<p><em class="info"><%= l(:text_session_expiration_settings) %></em></p> |
|
| 35 |
</fieldset> |
|
| 36 |
|
|
| 37 |
<%= submit_tag l(:button_save) %> |
|
| 38 |
<% end %> |
|
| .svn/pristine/12/124c8ea6c27371f24076da94e97c521fc176d638.svn-base | ||
|---|---|---|
| 1 |
require File.expand_path('../../test_helper', __FILE__)
|
|
| 2 |
|
|
| 3 |
class FilesControllerTest < ActionController::TestCase |
|
| 4 |
fixtures :projects, :trackers, :issue_statuses, :issues, |
|
| 5 |
:enumerations, :users, :issue_categories, |
|
| 6 |
:projects_trackers, |
|
| 7 |
:roles, |
|
| 8 |
:member_roles, |
|
| 9 |
:members, |
|
| 10 |
:enabled_modules, |
|
| 11 |
:workflows, |
|
| 12 |
:journals, :journal_details, |
|
| 13 |
:attachments, |
|
| 14 |
:versions |
|
| 15 |
|
|
| 16 |
def setup |
|
| 17 |
@controller = FilesController.new |
|
| 18 |
@request = ActionController::TestRequest.new |
|
| 19 |
@response = ActionController::TestResponse.new |
|
| 20 |
@request.session[:user_id] = nil |
|
| 21 |
Setting.default_language = 'en' |
|
| 22 |
end |
|
| 23 |
|
|
| 24 |
def test_index |
|
| 25 |
get :index, :project_id => 1 |
|
| 26 |
assert_response :success |
|
| 27 |
assert_template 'index' |
|
| 28 |
assert_not_nil assigns(:containers) |
|
| 29 |
|
|
| 30 |
# file attached to the project |
|
| 31 |
assert_tag :a, :content => 'project_file.zip', |
|
| 32 |
:attributes => { :href => '/attachments/download/8/project_file.zip' }
|
|
| 33 |
|
|
| 34 |
# file attached to a project's version |
|
| 35 |
assert_tag :a, :content => 'version_file.zip', |
|
| 36 |
:attributes => { :href => '/attachments/download/9/version_file.zip' }
|
|
| 37 |
end |
|
| 38 |
|
|
| 39 |
def test_create_file |
|
| 40 |
set_tmp_attachments_directory |
|
| 41 |
@request.session[:user_id] = 2 |
|
| 42 |
Setting.notified_events = ['file_added'] |
|
| 43 |
ActionMailer::Base.deliveries.clear |
|
| 44 |
|
|
| 45 |
assert_difference 'Attachment.count' do |
|
| 46 |
post :create, :project_id => 1, :version_id => '', |
|
| 47 |
:attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
|
|
| 48 |
assert_response :redirect |
|
| 49 |
end |
|
| 50 |
assert_redirected_to '/projects/ecookbook/files' |
|
| 51 |
a = Attachment.find(:first, :order => 'created_on DESC') |
|
| 52 |
assert_equal 'testfile.txt', a.filename |
|
| 53 |
assert_equal Project.find(1), a.container |
|
| 54 |
|
|
| 55 |
mail = ActionMailer::Base.deliveries.last |
|
| 56 |
assert_kind_of TMail::Mail, mail |
|
| 57 |
assert_equal "[eCookbook] New file", mail.subject |
|
| 58 |
assert mail.body.include?('testfile.txt')
|
|
| 59 |
end |
|
| 60 |
|
|
| 61 |
def test_create_version_file |
|
| 62 |
set_tmp_attachments_directory |
|
| 63 |
@request.session[:user_id] = 2 |
|
| 64 |
Setting.notified_events = ['file_added'] |
|
| 65 |
|
|
| 66 |
assert_difference 'Attachment.count' do |
|
| 67 |
post :create, :project_id => 1, :version_id => '2', |
|
| 68 |
:attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
|
|
| 69 |
assert_response :redirect |
|
| 70 |
end |
|
| 71 |
assert_redirected_to '/projects/ecookbook/files' |
|
| 72 |
a = Attachment.find(:first, :order => 'created_on DESC') |
|
| 73 |
assert_equal 'testfile.txt', a.filename |
|
| 74 |
assert_equal Version.find(2), a.container |
|
| 75 |
end |
|
| 76 |
|
|
| 77 |
end |
|
| .svn/pristine/12/129a1be9ab4fb00e9e24a4a97d3003da6c507962.svn-base | ||
|---|---|---|
| 1 |
<% if @project.boards.any? %> |
|
| 2 |
<table class="list"> |
|
| 3 |
<thead><tr> |
|
| 4 |
<th><%= l(:label_board) %></th> |
|
| 5 |
<th><%= l(:field_description) %></th> |
|
| 6 |
<th></th> |
|
| 7 |
<th></th> |
|
| 8 |
</tr></thead> |
|
| 9 |
<tbody> |
|
| 10 |
<% @project.boards.each do |board| |
|
| 11 |
next if board.new_record? %> |
|
| 12 |
<tr class="<%= cycle 'odd', 'even' %>"> |
|
| 13 |
<td><%=h board.name %></td> |
|
| 14 |
<td><%=h board.description %></td> |
|
| 15 |
<td align="center"> |
|
| 16 |
<% if authorize_for("boards", "edit") %>
|
|
| 17 |
<%= reorder_links('board', {:controller => 'boards', :action => 'edit', :project_id => @project, :id => board}) %>
|
|
| 18 |
<% end %> |
|
| 19 |
</td> |
|
| 20 |
<td class="buttons"> |
|
| 21 |
<%= link_to_if_authorized l(:button_edit), {:controller => 'boards', :action => 'edit', :project_id => @project, :id => board}, :class => 'icon icon-edit' %>
|
|
| 22 |
<%= link_to_if_authorized l(:button_delete), {:controller => 'boards', :action => 'destroy', :project_id => @project, :id => board}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %>
|
|
| 23 |
</td> |
|
| 24 |
</tr> |
|
| 25 |
<% end %> |
|
| 26 |
</tbody> |
|
| 27 |
</table> |
|
| 28 |
<% else %> |
|
| 29 |
<p class="nodata"><%= l(:label_no_data) %></p> |
|
| 30 |
<% end %> |
|
| 31 |
|
|
| 32 |
<p><%= link_to_if_authorized l(:label_board_new), {:controller => 'boards', :action => 'new', :project_id => @project}, :class => 'icon icon-add' %></p>
|
|
| .svn/pristine/12/12d2aa017b97ff487eca5cc334afe4f6ec1d0dc6.svn-base | ||
|---|---|---|
| 1 |
class NotifyMail < ActionMailer::Base |
|
| 2 |
|
|
| 3 |
helper :mail |
|
| 4 |
|
|
| 5 |
def signup(txt) |
|
| 6 |
body(:name => txt) |
|
| 7 |
end |
|
| 8 |
|
|
| 9 |
def multipart |
|
| 10 |
recipients 'some_address@email.com' |
|
| 11 |
subject 'multi part email' |
|
| 12 |
from "another_user@email.com" |
|
| 13 |
content_type 'multipart/alternative' |
|
| 14 |
|
|
| 15 |
part :content_type => "text/html", :body => render_message("multipart_html", {})
|
|
| 16 |
part "text/plain" do |p| |
|
| 17 |
p.body = render_message("multipart_plain", {})
|
|
| 18 |
end |
|
| 19 |
end |
|
| 20 |
|
|
| 21 |
def implicit_multipart |
|
| 22 |
recipients 'some_address@email.com' |
|
| 23 |
subject 'multi part email' |
|
| 24 |
from "another_user@email.com" |
|
| 25 |
end |
|
| 26 |
end |
|
| .svn/pristine/12/12e2bd6b115cd00dd763ce32dbfae0382d38cea8.svn-base | ||
|---|---|---|
| 1 |
desc 'Updates and checks locales against en.yml' |
|
| 2 |
task :locales do |
|
| 3 |
%w(locales:update locales:check_interpolation).collect do |task| |
|
| 4 |
Rake::Task[task].invoke |
|
| 5 |
end |
|
| 6 |
end |
|
| 7 |
|
|
| 8 |
namespace :locales do |
|
| 9 |
desc 'Updates language files based on en.yml content (only works for new top level keys).' |
|
| 10 |
task :update do |
|
| 11 |
dir = ENV['DIR'] || './config/locales' |
|
| 12 |
|
|
| 13 |
en_strings = YAML.load(File.read(File.join(dir,'en.yml')))['en'] |
|
| 14 |
|
|
| 15 |
files = Dir.glob(File.join(dir,'*.{yaml,yml}'))
|
|
| 16 |
files.sort.each do |file| |
|
| 17 |
puts "Updating file #{file}"
|
|
| 18 |
file_strings = YAML.load(File.read(file)) |
|
| 19 |
file_strings = file_strings[file_strings.keys.first] |
|
| 20 |
|
|
| 21 |
missing_keys = en_strings.keys - file_strings.keys |
|
| 22 |
next if missing_keys.empty? |
|
| 23 |
|
|
| 24 |
puts "==> Missing #{missing_keys.size} keys (#{missing_keys.join(', ')})"
|
|
| 25 |
lang = File.open(file, 'a') |
|
| 26 |
|
|
| 27 |
missing_keys.each do |key| |
|
| 28 |
{key => en_strings[key]}.to_yaml.each_line do |line|
|
|
| 29 |
next if line =~ /^---/ || line.empty? |
|
| 30 |
puts " #{line}"
|
|
| 31 |
lang << " #{line}"
|
|
| 32 |
end |
|
| 33 |
end |
|
| 34 |
|
|
| 35 |
lang.close |
|
| 36 |
end |
|
| 37 |
end |
|
| 38 |
|
|
| 39 |
desc 'Checks interpolation arguments in locals against en.yml' |
|
| 40 |
task :check_interpolation do |
|
| 41 |
dir = ENV['DIR'] || './config/locales' |
|
| 42 |
en_strings = YAML.load(File.read(File.join(dir,'en.yml')))['en'] |
|
| 43 |
files = Dir.glob(File.join(dir,'*.{yaml,yml}'))
|
|
| 44 |
files.sort.each do |file| |
|
| 45 |
puts "parsing #{file}..."
|
|
| 46 |
file_strings = YAML.load_file(file) |
|
| 47 |
unless file_strings.is_a?(Hash) |
|
| 48 |
puts "#{file}: content is not a Hash (#{file_strings.class.name})"
|
|
| 49 |
next |
|
| 50 |
end |
|
| 51 |
unless file_strings.keys.size == 1 |
|
| 52 |
puts "#{file}: content has multiple keys (#{file_strings.keys.size})"
|
|
| 53 |
next |
|
| 54 |
end |
|
| 55 |
file_strings = file_strings[file_strings.keys.first] |
|
| 56 |
|
|
| 57 |
file_strings.each do |key, string| |
|
| 58 |
next unless string.is_a?(String) |
|
| 59 |
string.scan /%\{\w+\}/ do |match|
|
|
| 60 |
unless en_strings[key].nil? || en_strings[key].include?(match) |
|
| 61 |
puts "#{file}: #{key} uses #{match} not found in en.yml"
|
|
| 62 |
end |
|
| 63 |
end |
|
| 64 |
end |
|
| 65 |
end |
|
| 66 |
end |
|
| 67 |
|
|
| 68 |
desc <<-END_DESC |
|
| 69 |
Removes a translation string from all locale file (only works for top-level childless non-multiline keys, probably doesn\'t work on windows). |
|
| 70 |
|
|
| 71 |
This task does not work on Ruby 1.8.6. |
|
| 72 |
You need to use Ruby 1.8.7 or later. |
|
| 73 |
|
|
| 74 |
Options: |
|
| 75 |
key=key_1,key_2 Comma-separated list of keys to delete |
|
| 76 |
skip=en,de Comma-separated list of locale files to ignore (filename without extension) |
|
| 77 |
END_DESC |
|
| 78 |
|
|
| 79 |
task :remove_key do |
|
| 80 |
dir = ENV['DIR'] || './config/locales' |
|
| 81 |
files = Dir.glob(File.join(dir,'*.yml')) |
|
| 82 |
skips = ENV['skip'] ? Regexp.union(ENV['skip'].split(',')) : nil
|
|
| 83 |
deletes = ENV['key'] ? Regexp.union(ENV['key'].split(',')) : nil
|
|
| 84 |
# Ignore multiline keys (begin with | or >) and keys with children (nothing meaningful after :) |
|
| 85 |
delete_regex = /\A #{deletes}: +[^\|>\s#].*\z/
|
|
| 86 |
|
|
| 87 |
files.each do |path| |
|
| 88 |
# Skip certain locales |
|
| 89 |
(puts "Skipping #{path}"; next) if File.basename(path, ".yml") =~ skips
|
|
| 90 |
puts "Deleting selected keys from #{path}"
|
|
| 91 |
orig_content = File.open(path, 'r') {|file| file.read}
|
|
| 92 |
File.open(path, 'w') {|file| orig_content.each_line {|line| file.puts line unless line.chomp =~ delete_regex}}
|
|
| 93 |
end |
|
| 94 |
end |
|
| 95 |
|
|
| 96 |
desc <<-END_DESC |
|
| 97 |
Adds a new top-level translation string to all locale file (only works for childless keys, probably doesn\'t work on windows, doesn't check for duplicates). |
|
| 98 |
|
|
| 99 |
Options: |
|
| 100 |
key="some_key=foo" |
|
| 101 |
key1="another_key=bar" |
|
| 102 |
key_fb="foo=bar" Keys to add in the form key=value, every option of the form key[,\\d,_*] will be recognised |
|
| 103 |
skip=en,de Comma-separated list of locale files to ignore (filename without extension) |
|
| 104 |
END_DESC |
|
| 105 |
|
|
| 106 |
task :add_key do |
|
| 107 |
dir = ENV['DIR'] || './config/locales' |
|
| 108 |
files = Dir.glob(File.join(dir,'*.yml')) |
|
| 109 |
skips = ENV['skip'] ? Regexp.union(ENV['skip'].split(',')) : nil
|
|
| 110 |
keys_regex = /\Akey(\d+|_.+)?\z/ |
|
| 111 |
adds = ENV.reject {|k,v| !(k =~ keys_regex)}.values.collect {|v| Array.new v.split("=",2)}
|
|
| 112 |
key_list = adds.collect {|v| v[0]}.join(", ")
|
|
| 113 |
|
|
| 114 |
files.each do |path| |
|
| 115 |
# Skip certain locales |
|
| 116 |
(puts "Skipping #{path}"; next) if File.basename(path, ".yml") =~ skips
|
|
| 117 |
# TODO: Check for dupliate/existing keys |
|
| 118 |
puts "Adding #{key_list} to #{path}"
|
|
| 119 |
File.open(path, 'a') do |file| |
|
| 120 |
adds.each do |kv| |
|
| 121 |
Hash[*kv].to_yaml.each_line do |line| |
|
| 122 |
file.puts " #{line}" unless (line =~ /^---/ || line.empty?)
|
|
| 123 |
end |
|
| 124 |
end |
|
| 125 |
end |
|
| 126 |
end |
|
| 127 |
end |
|
| 128 |
|
|
| 129 |
desc 'Duplicates a key. Exemple rake locales:dup key=foo new_key=bar' |
|
| 130 |
task :dup do |
|
| 131 |
dir = ENV['DIR'] || './config/locales' |
|
| 132 |
files = Dir.glob(File.join(dir,'*.yml')) |
|
| 133 |
skips = ENV['skip'] ? Regexp.union(ENV['skip'].split(',')) : nil
|
|
| 134 |
key = ENV['key'] |
|
| 135 |
new_key = ENV['new_key'] |
|
| 136 |
abort "Missing key argument" if key.blank? |
|
| 137 |
abort "Missing new_key argument" if new_key.blank? |
|
| 138 |
|
|
| 139 |
files.each do |path| |
|
| 140 |
# Skip certain locales |
|
| 141 |
(puts "Skipping #{path}"; next) if File.basename(path, ".yml") =~ skips
|
|
| 142 |
puts "Adding #{new_key} to #{path}"
|
|
| 143 |
|
|
| 144 |
strings = File.read(path) |
|
| 145 |
unless strings =~ /^( #{key}: .+)$/
|
|
| 146 |
puts "Key not found in #{path}"
|
|
| 147 |
next |
|
| 148 |
end |
|
| 149 |
line = $1 |
|
| 150 |
|
|
| 151 |
File.open(path, 'a') do |file| |
|
| 152 |
file.puts(line.sub(key, new_key)) |
|
| 153 |
end |
|
| 154 |
end |
|
| 155 |
end |
|
| 156 |
|
|
| 157 |
desc 'Check parsing yaml by psych library on Ruby 1.9.' |
|
| 158 |
|
|
| 159 |
# On Fedora 12 and 13, if libyaml-devel is available, |
|
| 160 |
# in case of installing by rvm, |
|
| 161 |
# Ruby 1.9 default yaml library is psych. |
|
| 162 |
|
|
| 163 |
task :check_parsing_by_psych do |
|
| 164 |
begin |
|
| 165 |
require 'psych' |
|
| 166 |
parser = Psych::Parser.new |
|
| 167 |
dir = ENV['DIR'] || './config/locales' |
|
| 168 |
files = Dir.glob(File.join(dir,'*.yml')) |
|
| 169 |
files.sort.each do |filename| |
|
| 170 |
next if File.directory? filename |
|
| 171 |
puts "parsing #{filename}..."
|
|
| 172 |
begin |
|
| 173 |
parser.parse File.open(filename) |
|
| 174 |
rescue Exception => e1 |
|
| 175 |
puts(e1.message) |
|
| 176 |
puts("")
|
|
| 177 |
end |
|
| 178 |
end |
|
| 179 |
rescue Exception => e |
|
| 180 |
puts(e.message) |
|
| 181 |
end |
|
| 182 |
end |
|
| 183 |
end |
|
Also available in: Unified diff