Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
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
PSDI Army
yii2
Commits
a37b35a4
Commit
a37b35a4
authored
Jan 27, 2014
by
Alexander Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #1897
- Gii diff markup is now copy paste friendly - Removed StringHelper::diff() - Moved phpspec/php-diff dependency from yiisoft/yii2 to yiisoft/yii2-gii
parent
1b4cec66
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
131 additions
and
57 deletions
+131
-57
CodeFile.php
extensions/gii/CodeFile.php
+22
-2
main.css
extensions/gii/assets/main.css
+4
-4
DiffRendererHtmlInline.php
extensions/gii/components/DiffRendererHtmlInline.php
+103
-0
composer.json
extensions/gii/composer.json
+2
-1
composer.json
framework/composer.json
+0
-1
BaseStringHelper.php
framework/helpers/BaseStringHelper.php
+0
-49
No files found.
extensions/gii/CodeFile.php
View file @
a37b35a4
...
...
@@ -9,9 +9,9 @@ namespace yii\gii;
use
Yii
;
use
yii\base\Object
;
use
yii\gii\components\DiffRendererHtmlInline
;
use
yii\gii\components\TextDiff
;
use
yii\helpers\Html
;
use
yii\helpers\StringHelper
;
/**
* CodeFile represents a code file to be generated.
...
...
@@ -147,9 +147,29 @@ class CodeFile extends Object
if
(
in_array
(
$type
,
[
'jpg'
,
'gif'
,
'png'
,
'exe'
]))
{
return
false
;
}
elseif
(
$this
->
operation
===
self
::
OP_OVERWRITE
)
{
return
StringHelper
::
d
iff
(
file
(
$this
->
path
),
$this
->
content
);
return
$this
->
renderD
iff
(
file
(
$this
->
path
),
$this
->
content
);
}
else
{
return
''
;
}
}
private
function
renderDiff
(
$lines1
,
$lines2
)
{
if
(
!
is_array
(
$lines1
))
{
$lines1
=
explode
(
"
\n
"
,
$lines1
);
}
if
(
!
is_array
(
$lines2
))
{
$lines2
=
explode
(
"
\n
"
,
$lines2
);
}
foreach
(
$lines1
as
$i
=>
$line
)
{
$lines1
[
$i
]
=
rtrim
(
$line
,
"
\r\n
"
);
}
foreach
(
$lines2
as
$i
=>
$line
)
{
$lines2
[
$i
]
=
rtrim
(
$line
,
"
\r\n
"
);
}
$renderer
=
new
DiffRendererHtmlInline
();
$diff
=
new
\Diff
(
$lines1
,
$lines2
);
return
$diff
->
render
(
$renderer
);
}
}
extensions/gii/assets/main.css
View file @
a37b35a4
...
...
@@ -148,10 +148,6 @@ body {
font-weight
:
normal
;
color
:
#999
;
width
:
5px
;
-webkit-user-select
:
none
;
-moz-user-select
:
none
;
-ms-user-select
:
none
;
user-select
:
none
;
}
.Differences
td
{
...
...
@@ -214,6 +210,10 @@ body {
background
:
#e99
;
}
.DifferencesInline
th
[
data-line-number
]
:before
{
content
:
attr
(
data-line-number
);
}
/* additional styles for typeahead.js-bootstrap.css */
.twitter-typeahead
{
display
:
block
!important
;
...
...
extensions/gii/components/DiffRendererHtmlInline.php
0 → 100644
View file @
a37b35a4
<?php
namespace
yii\gii\components
;
class
DiffRendererHtmlInline
extends
\Diff_Renderer_Html_Array
{
/**
* Render a and return diff with changes between the two sequences
* displayed inline (under each other)
*
* @return string The generated inline diff.
*/
public
function
render
()
{
$changes
=
parent
::
render
();
$html
=
''
;
if
(
empty
(
$changes
))
{
return
$html
;
}
$html
.=
'<table class="Differences DifferencesInline">'
;
$html
.=
'<thead>'
;
$html
.=
'<tr>'
;
$html
.=
'<th>Old</th>'
;
$html
.=
'<th>New</th>'
;
$html
.=
'<th>Differences</th>'
;
$html
.=
'</tr>'
;
$html
.=
'</thead>'
;
foreach
(
$changes
as
$i
=>
$blocks
)
{
// If this is a separate block, we're condensing code so output ...,
// indicating a significant portion of the code has been collapsed as
// it is the same
if
(
$i
>
0
)
{
$html
.=
'<tbody class="Skipped">'
;
$html
.=
'<th data-line-number="…"></th>'
;
$html
.=
'<th data-line-number="…"></th>'
;
$html
.=
'<td> </td>'
;
$html
.=
'</tbody>'
;
}
foreach
(
$blocks
as
$change
)
{
$html
.=
'<tbody class="Change'
.
ucfirst
(
$change
[
'tag'
])
.
'">'
;
// Equal changes should be shown on both sides of the diff
if
(
$change
[
'tag'
]
==
'equal'
)
{
foreach
(
$change
[
'base'
][
'lines'
]
as
$no
=>
$line
)
{
$fromLine
=
$change
[
'base'
][
'offset'
]
+
$no
+
1
;
$toLine
=
$change
[
'changed'
][
'offset'
]
+
$no
+
1
;
$html
.=
'<tr>'
;
$html
.=
'<th data-line-number="'
.
$fromLine
.
'"></th>'
;
$html
.=
'<th data-line-number="'
.
$toLine
.
'"></th>'
;
$html
.=
'<td class="Left">'
.
$line
.
'</td>'
;
$html
.=
'</tr>'
;
}
}
// Added lines only on the right side
else
if
(
$change
[
'tag'
]
==
'insert'
)
{
foreach
(
$change
[
'changed'
][
'lines'
]
as
$no
=>
$line
)
{
$toLine
=
$change
[
'changed'
][
'offset'
]
+
$no
+
1
;
$html
.=
'<tr>'
;
$html
.=
'<th data-line-number=" "></th>'
;
$html
.=
'<th data-line-number="'
.
$toLine
.
'"></th>'
;
$html
.=
'<td class="Right"><ins>'
.
$line
.
'</ins> </td>'
;
$html
.=
'</tr>'
;
}
}
// Show deleted lines only on the left side
else
if
(
$change
[
'tag'
]
==
'delete'
)
{
foreach
(
$change
[
'base'
][
'lines'
]
as
$no
=>
$line
)
{
$fromLine
=
$change
[
'base'
][
'offset'
]
+
$no
+
1
;
$html
.=
'<tr>'
;
$html
.=
'<th data-line-number="'
.
$fromLine
.
'"></th>'
;
$html
.=
'<th data-line-number=" "></th>'
;
$html
.=
'<td class="Left"><del>'
.
$line
.
'</del> </td>'
;
$html
.=
'</tr>'
;
}
}
// Show modified lines on both sides
else
if
(
$change
[
'tag'
]
==
'replace'
)
{
foreach
(
$change
[
'base'
][
'lines'
]
as
$no
=>
$line
)
{
$fromLine
=
$change
[
'base'
][
'offset'
]
+
$no
+
1
;
$html
.=
'<tr>'
;
$html
.=
'<th data-line-number="'
.
$fromLine
.
'"></th>'
;
$html
.=
'<th data-line-number=" "></th>'
;
$html
.=
'<td class="Left"><span>'
.
$line
.
'</span></td>'
;
$html
.=
'</tr>'
;
}
foreach
(
$change
[
'changed'
][
'lines'
]
as
$no
=>
$line
)
{
$toLine
=
$change
[
'changed'
][
'offset'
]
+
$no
+
1
;
$html
.=
'<tr>'
;
$html
.=
'<th data-line-number="'
.
$toLine
.
'"></th>'
;
$html
.=
'<th data-line-number=" "></th>'
;
$html
.=
'<td class="Right"><span>'
.
$line
.
'</span></td>'
;
$html
.=
'</tr>'
;
}
}
$html
.=
'</tbody>'
;
}
}
$html
.=
'</table>'
;
return
$html
;
}
}
\ No newline at end of file
extensions/gii/composer.json
View file @
a37b35a4
...
...
@@ -19,7 +19,8 @@
],
"require"
:
{
"yiisoft/yii2"
:
"*"
,
"yiisoft/yii2-bootstrap"
:
"*"
"yiisoft/yii2-bootstrap"
:
"*"
,
"phpspec/php-diff"
:
">=1.0.2"
},
"autoload"
:
{
"psr-4"
:
{
"yii
\\
gii
\\
"
:
""
}
...
...
framework/composer.json
View file @
a37b35a4
...
...
@@ -54,7 +54,6 @@
"lib-pcre"
:
"*"
,
"yiisoft/yii2-composer"
:
"*"
,
"yiisoft/jquery"
:
"~2.0 | ~1.10"
,
"phpspec/php-diff"
:
">=1.0.2"
,
"ezyang/htmlpurifier"
:
"4.6.*"
,
"michelf/php-markdown"
:
"1.3.*"
},
...
...
framework/helpers/BaseStringHelper.php
View file @
a37b35a4
...
...
@@ -88,53 +88,4 @@ class BaseStringHelper
return
''
;
}
}
/**
* Compares two strings or string arrays, and return their differences.
* This is a wrapper of the [phpspec/php-diff](https://packagist.org/packages/phpspec/php-diff) package.
* @param string|array $lines1 the first string or string array to be compared. If it is a string,
* it will be converted into a string array by breaking at newlines.
* @param string|array $lines2 the second string or string array to be compared. If it is a string,
* it will be converted into a string array by breaking at newlines.
* @param string $format the output format. It must be 'inline', 'unified', 'context', 'side-by-side', or 'array'.
* @return string|array the comparison result. An array is returned if `$format` is 'array'. For all other
* formats, a string is returned.
* @throws InvalidParamException if the format is invalid.
*/
public
static
function
diff
(
$lines1
,
$lines2
,
$format
=
'inline'
)
{
if
(
!
is_array
(
$lines1
))
{
$lines1
=
explode
(
"
\n
"
,
$lines1
);
}
if
(
!
is_array
(
$lines2
))
{
$lines2
=
explode
(
"
\n
"
,
$lines2
);
}
foreach
(
$lines1
as
$i
=>
$line
)
{
$lines1
[
$i
]
=
rtrim
(
$line
,
"
\r\n
"
);
}
foreach
(
$lines2
as
$i
=>
$line
)
{
$lines2
[
$i
]
=
rtrim
(
$line
,
"
\r\n
"
);
}
switch
(
$format
)
{
case
'inline'
:
$renderer
=
new
\Diff_Renderer_Html_Inline
();
break
;
case
'array'
:
$renderer
=
new
\Diff_Renderer_Html_Array
();
break
;
case
'side-by-side'
:
$renderer
=
new
\Diff_Renderer_Html_SideBySide
();
break
;
case
'context'
:
$renderer
=
new
\Diff_Renderer_Text_Context
();
break
;
case
'unified'
:
$renderer
=
new
\Diff_Renderer_Text_Unified
();
break
;
default
:
throw
new
InvalidParamException
(
"Output format must be 'inline', 'side-by-side', 'array', 'context' or 'unified'."
);
}
$diff
=
new
\Diff
(
$lines1
,
$lines2
);
return
$diff
->
render
(
$renderer
);
}
}
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