Skip to content

V2 css parser document #164

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

Open
wants to merge 12 commits into
base: v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove deprecated API of positional arguments
  • Loading branch information
stoivo committed Jun 18, 2024
commit 6ce174a44a2c382f63ca669e2d5cc7905001da30
30 changes: 6 additions & 24 deletions lib/css_parser/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -410,17 +410,11 @@ def compact! # :nodoc:
# See add_block! for options.
#
# Deprecated: originally accepted three params: `uri`, `base_uri` and `media_types`
def load_uri!(uri, options = {}, deprecated = nil)
def load_uri!(uri, options = {})
uri = Addressable::URI.parse(uri) unless uri.respond_to? :scheme

opts = {base_uri: nil, media_types: :all}

if options.is_a? Hash
opts.merge!(options)
else
opts[:base_uri] = options if options.is_a? String
opts[:media_types] = deprecated if deprecated
end
opts.merge!(options)

if uri.scheme == 'file' or uri.scheme.nil?
uri.path = File.expand_path(uri.path)
Expand All @@ -438,15 +432,9 @@ def load_uri!(uri, options = {}, deprecated = nil)
end

# Load a local CSS file.
def load_file!(file_name, options = {}, deprecated = nil)
def load_file!(file_name, options = {})
opts = {base_dir: nil, media_types: :all}

if options.is_a? Hash
opts.merge!(options)
else
opts[:base_dir] = options if options.is_a? String
opts[:media_types] = deprecated if deprecated
end
opts.merge!(options)

file_path = @options[:file_resource]
.find_file(file_name, base_dir: opts[:base_dir])
Expand All @@ -462,15 +450,9 @@ def load_file!(file_name, options = {}, deprecated = nil)
end

# Load a local CSS string.
def load_string!(src, options = {}, deprecated = nil)
def load_string!(src, options = {})
opts = {base_dir: nil, media_types: :all}

if options.is_a? Hash
opts.merge!(options)
else
opts[:base_dir] = options if options.is_a? String
opts[:media_types] = deprecated if deprecated
end
opts.merge!(options)

add_block!(src, opts)
end
Expand Down
2 changes: 1 addition & 1 deletion test/test_css_parser_loading.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def test_loading_a_string

def test_following_at_import_rules_local
base_dir = File.expand_path('fixtures', __dir__)
@cp.load_file!('import1.css', base_dir)
@cp.load_file!('import1.css', base_dir: base_dir)

# from '/import1.css'
assert_equal 'color: lime;', @cp.find_by_selector('div').join(' ')
Expand Down