Skip to content
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

V2: I have a working version with crass, Css parsing imporved #156

Merged
merged 7 commits into from
May 28, 2024

Conversation

stoivo
Copy link
Contributor

@stoivo stoivo commented May 27, 2024

I created a new v2 branch and good in some more of the commits on master. Maybe we can make this the base for v2. I have more changes we should do before releasing but you can have a look and give tel me what you think?

One of the things I would like to do is to remove depreciation and remove unused things from regexps.rb

@stoivo stoivo changed the title I have a working version with crass, Css parsing imporved V2: I have a working version with crass, Css parsing imporved May 27, 2024
@grosser
Copy link
Contributor

grosser commented May 27, 2024

I already rebased v2 on master to make this easier to read, but the diff here did not change, can you try and rebase again ?

Comment on lines +130 to +131
case node
in node: :style_rule
Copy link
Contributor

@grosser grosser May 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use this instead:

case node[:node]
when :style_rule

(and then break down further based on name inside of these)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can but why do you think this is better? I like the pattern matching code

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

either way is fine, was mostly thinking we could have 1 case for every type and then some method that handles each sub-type and that might be cleaner

Comment on lines +132 to +146
declarations = create_declaration_from_properties(node[:children])

add_rule_options = {
selectors: node[:selector][:value],
block: declarations,
media_types: current_media_queries
}
if options[:capture_offsets]
add_rule_options.merge!(
filename: options[:filename],
offset: node[:selector][:tokens].first[:pos]..node[:children].last[:pos]
)
end

add_rule!(**add_rule_options)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it make sense to have each of these blocks be a method ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to try to keep the main functionality here in add_block! but maybe I should do some work here to extract some more helper function. I will look at it in later PR if that's okay?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good, was mostly hard to keep all the structure in mind when reviewing/reading :)

assert_equal file_name, rules[1].filename
end

# http://github.com/premailer/css_parser/issues#issue/4
def test_capturing_offsets_from_remote_file
# TODO: test SSL locally
# TODO: cache request to make test not require internet (and so much faster)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add webmock so that will just break and we return stubbed replies ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think webmock here is the right choice too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

later PR?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah sure

Comment on lines +613 to +615
in node: :whitespace # nothing
in node: :semicolon # nothing
in node: :error # nothing
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we remove these 3 or even better add a "else raise" ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pattern patching. If none of the branches matches it will raise NoMatchingPatternError. I like that error because adds which node it received

One example

NoMatchingPatternError: {:node=>:style_rule, :selector=>{:node=>:selector, :value=>"body", :tokens=>[{:node=>:ident, :pos=>6, :raw=>"body", :value=>"body"}, {:node=>:whitespace, :pos=>10, :raw=>" "}]}, :children=>[{:node=>:whitespace, :pos=>12, :raw=>" "}, {:node=>:property, :name=>"font-size", :value=>"10pt", :children=>[{:node=>:whitespace, :pos=>23, :raw=>" "}, {:node=>:dimension, :pos=>24, :raw=>"10pt", :repr=>"10", :type=>:integer, :unit=>"pt", :value=>10}, {:node=>:whitespace, :pos=>28, :raw=>" "}], :important=>false, :tokens=>[{:node=>:ident, :pos=>13, :raw=>"font-size", :value=>"font-size"}, {:node=>:colon, :pos=>22, :raw=>":"}, {:node=>:whitespace, :pos=>23, :raw=>" "}, {:node=>:dimension, :pos=>24, :raw=>"10pt", :repr=>"10", :type=>:integer, :unit=>"pt", :value=>10}, {:node=>:whitespace, :pos=>28, :raw=>" "}]}]}

I think I need to add some more section for stuff like @keyframe

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh nice, did not realize they added that ✨

Copy link
Contributor

@grosser grosser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks pretty good ... no red flags at first sight 👍
... let's try to get as much as possible landed in master or v2 via smaller PRs so this PR is easier to read

@stoivo stoivo force-pushed the v2 branch 2 times, most recently from ebe56f6 to 806f91c Compare May 28, 2024 07:54
second argument to assert_raises is custom error message
Using ArgumentError sounds like a good idea since we received invalid
argument to this method, but this exception is suppose to be when you
pass the wrong number of arguments or missing keywords.
Error
  Your bundle only supports platforms ["arm64-darwin-22", "java"] but your local
@grosser grosser merged commit b22a873 into premailer:v2 May 28, 2024
6 checks passed
@stoivo stoivo deleted the v2 branch May 29, 2024 06:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants