-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from oneut/support_replaces
Support replaces
- Loading branch information
Showing
9 changed files
with
157 additions
and
18 deletions.
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
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,19 @@ | ||
package config | ||
|
||
type Replace struct { | ||
Search string | ||
Replace string | ||
Regexp bool | ||
} | ||
|
||
func (r *Replace) IsValid() bool { | ||
if r.Search == "" { | ||
return false | ||
} | ||
|
||
if r.Replace == "" { | ||
return false | ||
} | ||
|
||
return true | ||
} |
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
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,21 @@ | ||
package livereloadproxy | ||
|
||
import ( | ||
"regexp" | ||
) | ||
|
||
func NewSourceRegexpReplacer(search string, replace string) *SourceRegexpReplacer { | ||
return &SourceRegexpReplacer{ | ||
searchRegexp: regexp.MustCompile(search), | ||
replace: replace, | ||
} | ||
} | ||
|
||
type SourceRegexpReplacer struct { | ||
searchRegexp *regexp.Regexp | ||
replace string | ||
} | ||
|
||
func (s *SourceRegexpReplacer) Replace(value string) string { | ||
return s.searchRegexp.ReplaceAllString(value, s.replace) | ||
} |
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,17 @@ | ||
package livereloadproxy | ||
|
||
import ( | ||
"github.com/oneut/lrp/config" | ||
) | ||
|
||
func NewSourceReplacer(replaceConfig config.Replace) SourceReplacer { | ||
if replaceConfig.Regexp { | ||
return NewSourceRegexpReplacer(replaceConfig.Search, replaceConfig.Replace) | ||
} | ||
|
||
return NewSourceStringReplacer(replaceConfig.Search, replaceConfig.Replace) | ||
} | ||
|
||
type SourceReplacer interface { | ||
Replace(string) string | ||
} |
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,19 @@ | ||
package livereloadproxy | ||
|
||
import "strings" | ||
|
||
func NewSourceStringReplacer(search string, replace string) *SourceStringReplacer { | ||
return &SourceStringReplacer{ | ||
search: search, | ||
replace: replace, | ||
} | ||
} | ||
|
||
type SourceStringReplacer struct { | ||
search string | ||
replace string | ||
} | ||
|
||
func (s *SourceStringReplacer) Replace(value string) string { | ||
return strings.Replace(value, s.search, s.replace, -1) | ||
} |
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