Skip to content

Commit

Permalink
Merge pull request #201 from evolvingweb/v1.2.11
Browse files Browse the repository at this point in the history
Adding remove-html-comments option to diff command.
  • Loading branch information
kdborg authored Aug 22, 2024
2 parents e1aa291 + 2cbf794 commit 6ebe05f
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

Contains noteworthy changes made to SiteDiff.

## Version 1.2.11
- Change to the Drupal preset for absolute links. It no longer changes __domain__ to an empty string.
- Added an option to the 'diff' command to remove HTML comments from pages.

## Version 1.2.10
- Updated deployment to get Docker build.
- Removed some debug code.
Expand Down
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
- [selector](#selector)
- [sanitization](#sanitization)
- [ignore_whitespace](#ignore_whitespace)
- [remove_html_comments](#remove_html_comments)
- [before / after](#before--after)
- [includes](#incudes)
- [includes](#incudes)
- [dom_transform](#dom_transform)
- [remove](#remove)
- [strip](#strip)
Expand Down Expand Up @@ -61,7 +62,7 @@
- [Empty Attributes](#empty-attributes)
- [Acknowledgements](#acknowledgements)

## Introduction
## Introduction
SiteDiff makes it easy to see how a website changes. It can compare two similar
sites or it can show how a single site changed over time. It helps identify
undesirable changes to the site's HTML and it's a useful tool for conducting QA
Expand Down Expand Up @@ -393,6 +394,15 @@ On the command line, use `-w` or `--ignore-whitespace`.
sitediff diff -w
```

### remove_html_comments
Remove HTML comments from a page. Useful for Drupal sites with the theme debugging enabled.

On the command line, use `-c` or `--remove-html-comments`.

```bash
sitediff diff -c
```

### before / after

Applies rules to just one side of the comparison.
Expand Down Expand Up @@ -791,7 +801,7 @@ If you have an empty `<p/>` tag appearing in the diff, you can write the followi

### HTML Tag Formatting

There are times when the HTML tags do not have newlines between them on one of the sites you wish to compare. In this
There are times when the HTML tags do not have newlines between them on one of the sites you wish to compare. In this
case, these sanitzation rules are useful:
```yaml
- name: remove_space_before
Expand Down
7 changes: 7 additions & 0 deletions lib/sitediff.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ def initialize(config, cache, verbose: true, debug: false)
def sanitize(path_passed, read_results)
%i[before after].map do |tag|
html = read_results[tag].content
html = remove_html_comments(html) if @config.remove_html_comments

# TODO: See why encoding is empty while running tests.
#
# The presence of an "encoding" value used to be used to determine
Expand All @@ -117,6 +119,11 @@ def sanitize(path_passed, read_results)
end
end

# Remove HTML comments.
def remove_html_comments(html_content)
html_content.gsub(/<!--.*?-->/m, '')
end

##
# Process a set of read results.
#
Expand Down
2 changes: 2 additions & 0 deletions lib/sitediff/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ def self.init(options)
def diff(options)
@config.ignore_whitespace = options[:ignore_whitespace]
@config.export = options[:export]
@config.remove_html_comments = options[:remove_html_comments]

# Apply "paths" override, if any.
if options[:paths]
@config.paths = options[:paths]
Expand Down
9 changes: 8 additions & 1 deletion lib/sitediff/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ def version
default: false,
aliases: '-e',
desc: 'Export report to files. This option forces HTML format.'
option 'remove_html_comments',
type: :boolean,
default: false,
aliases: '-c',
desc: 'Remove HTML comments from the output.'
desc 'diff [OPTIONS] [CONFIG-FILE]',
'Compute diffs on configured URLs.'
##
Expand All @@ -126,9 +131,11 @@ def diff(config_file = nil)
:debug,
:report_format,
:before_report,
:after_report
:after_report,
:remove_html_comments
)
api_options[:cli_mode] = true
puts api_options
api.diff(api_options)
end

Expand Down
10 changes: 10 additions & 0 deletions lib/sitediff/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,16 @@ def ignore_whitespace=(ignore_whitespace)
@config['ignore_whitespace'] = ignore_whitespace
end

# Get remove_html_comments option
def remove_html_comments
@config['remove_html_comments']
end

# Set ignore_whitespace option
def remove_html_comments=(remove_html_comments)
@config['remove_html_comments'] = remove_html_comments
end

# Get export option
def export
@config['export']
Expand Down
2 changes: 1 addition & 1 deletion lib/sitediff/presets/drupal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ sanitization:
substitute: '\1'
- title: Strip domain names from absolute URLs
pattern: 'https?:\/\/[a-zA-Z0-9.:-]+'
substitute: '__domain__'
substitute: ''
- title: Strip form build ID
selector: input
pattern: 'autocomplete="off" data-drupal-selector="form-[-\w]{40,43}"'
Expand Down
2 changes: 1 addition & 1 deletion sitediff.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Gem::Specification.new do |s|
s.name = 'sitediff'
s.version = '1.2.10'
s.version = '1.2.11'
s.required_ruby_version = '>= 3.1.2'
s.summary = 'Compare two versions of a site with ease!'
s.description = <<DESC
Expand Down

0 comments on commit 6ebe05f

Please sign in to comment.