Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
O
OHR Support
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
97
Issues
97
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
OHR Support
Commits
0befef71
Commit
0befef71
authored
Oct 08, 2011
by
Holger Just
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add rake task to set magic comments for source encoding
parent
0ed5cb3f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
0 deletions
+31
-0
code.rake
lib/tasks/code.rake
+31
-0
No files found.
lib/tasks/code.rake
View file @
0befef71
#-- encoding: UTF-8
#-- copyright
# ChiliProject is a project management system.
#
...
...
@@ -29,4 +30,34 @@ namespace :code do
end
end
end
desc
"Set the magic encoding comment everywhere to UTF-8"
task
:source_encoding
do
shebang
=
'\s*#!.*?(\n|\r\n)'
magic_regex
=
/\A(
#{
shebang
}
)?\s*(#\W*(en)?coding:.*?$)/mi
magic_comment
=
'#-- encoding: UTF-8'
(
Dir
[
'script/**/**'
]
+
Dir
[
'**/**{.rb,.rake}'
]).
each
do
|
file_name
|
next
unless
File
.
file?
(
file_name
)
# We don't skip code here, as we need ALL code files to have UTF-8
# source encoding
file_content
=
File
.
read
(
file_name
)
if
file_content
=~
magic_regex
file_content
.
gsub!
(
magic_regex
,
"
\\
1
#{
magic_comment
}
"
)
else
if
file_content
.
start_with?
(
"#!"
)
# We have a shebang. Encoding comment is to put on the second line
file_content
.
sub!
(
/(\n|\r\n)/
,
"
\\
1
#{
magic_comment
}
\\
1"
)
else
file_content
=
magic_comment
+
"
\n
"
+
file_content
end
end
File
.
open
(
file_name
,
"w"
)
do
|
file
|
file
.
write
file_content
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment