Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
annotate
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
annotate
Commits
ed05a78e
Commit
ed05a78e
authored
Dec 28, 2008
by
Marcos Augusto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dont add whitespace on routes, and some minor stuff
parent
63467863
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
44 additions
and
25 deletions
+44
-25
annotate.gemspec
annotate.gemspec
+5
-5
annotate
bin/annotate
+1
-0
annotate.rb
lib/annotate.rb
+1
-1
annotate_routes.rb
lib/annotate/annotate_routes.rb
+5
-4
annotate_routes_spec.rb
spec/annotate/annotate_routes_spec.rb
+32
-15
No files found.
annotate.gemspec
View file @
ed05a78e
...
...
@@ -2,11 +2,11 @@
Gem
::
Specification
.
new
do
|
s
|
s
.
name
=
%q{annotate}
s
.
version
=
"2.2.
3
"
s
.
version
=
"2.2.
5
"
s
.
required_rubygems_version
=
Gem
::
Requirement
.
new
(
">= 0"
)
if
s
.
respond_to?
:required_rubygems_version
=
s
.
authors
=
[
"Marcos Piccinini"
]
s
.
date
=
%q{2008-12-2
6
}
s
.
date
=
%q{2008-12-2
8
}
s
.
default_executable
=
%q{annotate}
s
.
description
=
%q{Annotates Rails Models and Routes}
s
.
email
=
[
"x@nofxx.com"
]
...
...
@@ -26,14 +26,14 @@ Gem::Specification.new do |s|
s
.
specification_version
=
2
if
Gem
::
Version
.
new
(
Gem
::
RubyGemsVersion
)
>=
Gem
::
Version
.
new
(
'1.2.0'
)
then
s
.
add_development_dependency
(
%q<newgem>
,
[
">= 1.2.
1
"
])
s
.
add_development_dependency
(
%q<newgem>
,
[
">= 1.2.
2
"
])
s
.
add_development_dependency
(
%q<hoe>
,
[
">= 1.8.0"
])
else
s
.
add_dependency
(
%q<newgem>
,
[
">= 1.2.
1
"
])
s
.
add_dependency
(
%q<newgem>
,
[
">= 1.2.
2
"
])
s
.
add_dependency
(
%q<hoe>
,
[
">= 1.8.0"
])
end
else
s
.
add_dependency
(
%q<newgem>
,
[
">= 1.2.
1
"
])
s
.
add_dependency
(
%q<newgem>
,
[
">= 1.2.
2
"
])
s
.
add_dependency
(
%q<hoe>
,
[
">= 1.8.0"
])
end
end
bin/annotate
View file @
ed05a78e
...
...
@@ -15,6 +15,7 @@ end.parse!
begin
Rake
::
Task
[
task
].
invoke
#TODO: rescue only rake error
rescue
NameError
=>
e
puts
"Can`t find Rake. Are we in a Rails folder?"
end
lib/annotate.rb
View file @
ed05a78e
...
...
@@ -2,7 +2,7 @@ $:.unshift(File.dirname(__FILE__)) unless
$:
.
include?
(
File
.
dirname
(
__FILE__
))
||
$:
.
include?
(
File
.
expand_path
(
File
.
dirname
(
__FILE__
)))
module
Annotate
VERSION
=
'2.2.
3
'
VERSION
=
'2.2.
5
'
end
begin
...
...
lib/annotate/annotate_routes.rb
View file @
ed05a78e
...
...
@@ -17,21 +17,22 @@
# Released under the same license as Ruby. No Support. No Warranty.module AnnotateRoutes
#
module
AnnotateRoutes
PREFIX
=
"#== Route
Info
"
PREFIX
=
"#== Route
Map
"
def
self
.
do_annotate
routes_rb
=
File
.
join
(
"config"
,
"routes.rb"
)
header
=
PREFIX
+
"
\n
# Generated on
#{
Time
.
now
}
\n
#"
header
=
PREFIX
+
"
\n
# Generated on
#{
Time
.
now
.
strftime
(
"%d %b %Y %H:%M"
)
}
\n
#"
if
File
.
exists?
routes_rb
routes_map
=
`rake routes`
routes_map
=
routes_map
.
split
(
"
\n
"
)
routes_map
.
shift
# remove the first line of rake routes which is just a file path
routes_map
=
routes_map
.
inject
(
header
){
|
sum
,
line
|
sum
<<
"
\n
# "
<<
line
}
content = File.read(routes_rb)
content
= content.split(/^#== Route Info.*?
\n
/)#, ''
)
content
, old = content.split(/^#== Route .*?
\n
/
)
File.open(routes_rb, "wb") do |f|
f.puts content
[0] + "
\n\n
"
+ routes_map
f.puts content
.sub!(/
\n
?
\z
/, "
\n
")
+ routes_map
end
puts "Route file annotated."
else
puts "Can`t find routes.rb"
end
...
...
spec/annotate/annotate_routes_spec.rb
View file @
ed05a78e
...
...
@@ -7,24 +7,41 @@ describe AnnotateRoutes do
@mock_file
||=
mock
(
File
,
stubs
)
end
it
"should check if routes.rb exists"
do
File
.
should_receive
(
:join
).
with
(
"config"
,
"routes.rb"
).
and_return
(
mock_file
)
File
.
should_receive
(
:exists?
).
with
(
@mock_file
).
and_return
(
false
)
AnnotateRoutes
.
should_receive
(
:puts
).
with
(
"Can`t find routes.rb"
)
describe
"Annotate Job"
do
AnnotateRoutes
.
do_annotate
end
before
(
:each
)
do
File
.
should_receive
(
:join
).
with
(
"config"
,
"routes.rb"
).
and_return
(
"config/routes.rb"
)
end
it
"should annotate!"
do
File
.
should_receive
(
:join
).
with
(
"config"
,
"routes.rb"
).
and_return
(
"config/routes.rb"
)
File
.
should_receive
(
:exists?
).
with
(
"config/routes.rb"
).
and_return
(
true
)
AnnotateRoutes
.
should_receive
(
:`
).
with
(
"rake routes"
).
and_return
(
"bad line
\n
good line"
)
File
.
should_receive
(
:read
).
with
(
"config/routes.rb"
).
and_return
(
"bla"
)
File
.
should_receive
(
:open
).
with
(
"config/routes.rb"
,
"wb"
).
and_yield
(
mock_file
)
@mock_file
.
should_receive
(
:puts
).
with
(
/bla\n\n#== Route Info\n# Generated on .*\n#\n# good line/
)
it
"should check if routes.rb exists"
do
File
.
should_receive
(
:exists?
).
with
(
"config/routes.rb"
).
and_return
(
false
)
AnnotateRoutes
.
should_receive
(
:puts
).
with
(
"Can`t find routes.rb"
)
AnnotateRoutes
.
do_annotate
end
AnnotateRoutes
.
do_annotate
end
describe
"When Annotating"
do
before
(
:each
)
do
File
.
should_receive
(
:exists?
).
with
(
"config/routes.rb"
).
and_return
(
true
)
AnnotateRoutes
.
should_receive
(
:`
).
with
(
"rake routes"
).
and_return
(
"bad line
\n
good line"
)
File
.
should_receive
(
:open
).
with
(
"config/routes.rb"
,
"wb"
).
and_yield
(
mock_file
)
AnnotateRoutes
.
should_receive
(
:puts
).
with
(
"Route map annotated."
)
end
it
"should annotate and add a newline!"
do
File
.
should_receive
(
:read
).
with
(
"config/routes.rb"
).
and_return
(
"ActionController::Routing...
\n
foo"
)
@mock_file
.
should_receive
(
:puts
).
with
(
/ActionController::Routing...\nfoo\n#== Route Map\n# Generated on .*\n#\n# good line/
)
AnnotateRoutes
.
do_annotate
end
it
"should not add a newline if there are empty lines"
do
File
.
should_receive
(
:read
).
with
(
"config/routes.rb"
).
and_return
(
"ActionController::Routing...
\n
foo
\n
"
)
@mock_file
.
should_receive
(
:puts
).
with
(
/ActionController::Routing...\nfoo\n#== Route Map\n# Generated on .*\n#\n# good line/
)
AnnotateRoutes
.
do_annotate
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