-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added byte offsets to rule sets #85
Conversation
idk about this ... kind of neat feature ... but more work/memory for the 99% usecase @akzhan thoughts ? |
It's nice contribution, but undone. We need any use case to be bundled with (may be in examples folder or in wiki or read.me). |
Also it's not clear to detect line endings by Windows platform. We may use "read binary mode" to keep line endings of file. |
… On Thu, Mar 9, 2017 at 12:23 AM, Akzhan Abdulin ***@***.***> wrote:
Also it's not clear to detect line endings by Windows platform.
We may use "read binary mode" to keep line endings of file.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#85 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAAsZwR4JguYFEaEOPpY2YBTKWIMbJdbks5rj7cMgaJpZM4MXoM_>
.
|
@akzhan I can add documentation before merging, however, I'm not seeing a wiki, only the @grosser I can refactor so that we only collect offsets if an option is passed to To get around the additional optional arguments, we could subclass |
@G0dwin ok, we need a) a section in README. |
Alright: In addition, I added a benchmark rake task ( I also added a Let me know if there are any other changes that you would like to see before merging, big or small. Cheers, |
LGTM |
@@ -1,2 +1,3 @@ | |||
/pkg/ | |||
/Gemfile.lock |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the .gitignore
, the change was made in 0ed2f74. I'm going to take a closer look though, I'm not as familiar with the way that Github shows diffs, I'm surprised it's showing this and other changes as changes when they currently match the master.
@@ -53,6 +53,22 @@ parser.add_block!(css) | |||
parser.to_s | |||
=> #content { font-size: 13px; line-height: 1.2; } | |||
body { margin: 0 1em; } | |||
|
|||
# capturing byte offsets within a file | |||
parser.load_uri!('../style.css', {:base_uri => 'http://example.com/styles/inc/', :capture_offsets => true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prefer 1.9 hash , base_uri: 'http://'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can make this change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just landed readme update.
token = matches[0] | ||
|
||
# save the regex offset so that we know where in the file we are | ||
offset = Regexp.last_match.offset(0) if options[:capture_offsets] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might be worth extracting that into a local variable if this code is used a lot
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
options[:capture_offsets]
? Sure.
@@ -504,11 +577,11 @@ def read_remote_file(uri) # :nodoc: | |||
|
|||
res = http.get(uri.request_uri, {'User-Agent' => USER_AGENT, 'Accept-Encoding' => 'gzip'}) | |||
src = res.body | |||
charset = fh.respond_to?(:charset) ? fh.charset : 'utf-8' | |||
charset = res.respond_to?(:charset) ? res.encoding : 'utf-8' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should get rid of this charset detection and drop 1.8 ... but that's for another PR
@@ -1,3 +1,3 @@ | |||
module CssParser | |||
VERSION = "1.4.9".freeze | |||
VERSION = "1.4.10".freeze |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't change version in the PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This again seems to be coming from rebasing, I'll take a closer look.
cp_with_exceptions.load_uri!("#{@uri_base}/no-exist.xyz") | ||
end | ||
|
||
uri_regex = Regexp.new(Regexp.escape("#{@uri_base}/no-exist.xyz")) | ||
assert_match uri_regex, err.message |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this might be simpler and produce a more readable error
err.message.must_include "#{@uri_base}/no-exist.xyz"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This came from ed148aa
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed by e2c831e
|
||
def test_content_with_data | ||
rule = RuleSet.new('div', '{content: url(data:image/png;base64,LOTSOFSTUFF)}') | ||
assert_match (/image\/png;base64,LOTSOFSTUFF/), rule.to_s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rule.to_s.must_include
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed by e2c831e also
# Returns a string. | ||
def ignore_pattern(css, regex, options) | ||
# if we are capturing file offsets, replace the characters with spaces to retail the original positions | ||
return css.gsub(regex) { |m| ' ' * m.length } if options[:capture_offsets] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might be easier to read with ` if ... else ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
look ok ... lots of commits, so squash would be nice
Some commits related to rebase (Gemfile.lock, version up), don't worry. |
Just note that is't released as Other updates should be proposed by other pull requests. |
I have added some basic logic to the parser to capture byte offsets when scanning for rule sets and added a field to
RuleSet
to retain them. This will allow code coverage and lint utilities (for example) to report where in a file a particular rule was found (see the CSS code coverage utility I'm working on here: lingua-franca/marmara).There is still more work that needs to be done, primarily when it comes to differentiating files (from
@import
statement or otherwise), and when urls are expanded.