-
Notifications
You must be signed in to change notification settings - Fork 6
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
[Major Changes][Sprockets 3 for LESS] Using versionized classes #5
base: master
Are you sure you want to change the base?
Conversation
Thank you for this, I'll try to look into it soon! |
Thank You too. I have an idea how to fix the issue with the helpers ...but i am going to be out of the country for the next 3 weeks. Will continue working on that after i return. Thank You for the response and i can't wait to hear more from You :) |
051234a
to
27043b1
Compare
I added few more commits but rebased again and squashed all commits. I fixed the issue with the helpers, now all tests are passing for sprockets 2.x and 3.x . There is still some work left to be done for sprockets 4.x but that can be done in another pull request. Please review again this pull request and let me know what you think :) Thank you very much |
The tests are passing locally, on Travis they fail because travis somehow uses an older bundler version. Left a comment on this issue travis-ci/travis-ci#5831 . Hopefully someone will find a solution for travis. |
caca5a9
to
b295389
Compare
8f8be96
to
62733ac
Compare
656f969
to
90f77cc
Compare
@lloeki , can you please review this pull request again? I fixed some issues with the importer and also the function parsing. I removed also ruby 2.0 and 2.1.5 from Travis YML file since 2.0 is not maintained anymore and 2.1.5 causes issues with bundler (because Travis has a older version of travis on server) I also tested this implementation with sprockets 3.x with a real application and works fine . Let me know what you think. Thank you very much. |
I was seeing your commits pouring in, so waited for you to ping me back that you were done :-) I'll look into it soon. |
Thanks :) , i fixed a minor issue . Replaced "compact.flatten" with "flatten.compact" in lib/sprockets/less/functions.rb. Checked other places. Should be good to go now :) Support for Sprockets 4.x is not ready yet, but will continue on that on another pull request. |
5254e6f
to
4af6a32
Compare
2135777
to
d10018e
Compare
Hello. I am just curios :) @loeki did you had any chance to look at this pull request? :) |
The issue with the helpers was fixed. Had to hack it a bit though...but it works. Let me know if something needs to Be changed or refactored or something...Thanks a lot :) |
Wow it'd been so long since I've promised looking at this, sorry! Thanks a lot for your continued effort on this. I have a couple things to do but I'll be looking at it afterwards. |
It's been 5 months since last reply. Any chance of this getting reviewed? Please . |
Sorry, I'll have a look at it today. |
.travis.yml
Outdated
- 2.1.0 | ||
- 2.2.2 | ||
- 2.2.3 | ||
- 2.3.1 |
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.
Can we have 2.4 here too?
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.
added ruby 2.4.1 to travis
.travis.yml
Outdated
- 2.1.0 | ||
- 2.2.2 | ||
- 2.2.3 | ||
- 2.3.1 |
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.
Also, can those be specified as major.minor so that we get the latest patch automatically? I can't recall if Travis allows this.
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 don't think Travis has that ability .
|
||
# This is needed so that on rubygems.org we can see the actual date | ||
# of the published version due to changes in Rubygems repo over the last year(2015 - 2016) | ||
s.date = Date.today |
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 have an issue here with ruby 2.4 (ruby 2.3 plows through fine):
[!] There was an error parsing `Gemfile`:
[!] There was an error while loading `sprockets-less.gemspec`: uninitialized constant Date
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.
That is from bundler actually and i fixed it now.
lib/sprockets/less.rb
Outdated
# For Sprockets 2.x , although the file and the module name exist, | ||
# they can't be used because it will give errors about undefined methods, because this is included only on Sprockets::Base | ||
# and in order to use them we would have to subclass it and define methods to expire cache and other methods for registration , | ||
# which are not needed since Sprockets already knows about that using the environment instead internally |
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.
Extra space before know
. Also, can you hard-wrap this comment to 79?
lib/sprockets/less/functions.rb
Outdated
::Less::Parser.class_eval do | ||
attr_reader :tree | ||
|
||
|
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.
Remove that extra line.
lib/sprockets/less/functions.rb
Outdated
end | ||
|
||
return hash |
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.
Remove return
keyword.
lib/sprockets/less/functions.rb
Outdated
arr << { match: m, index: offset } unless m.nil? | ||
str = str[(offset + 1)..-1] | ||
end | ||
arr.uniq {|hash| hash[:match] } |
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.
Add blank line before implicit return value
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.
Also, missing space after {
default_less_config[:load_paths] = default_less_config[:load_paths].concat(default_less_config[:paths]) if default_less_config[:paths].is_a?(Array) | ||
less = default_less_config | ||
less = merge_less_options(less.dup, @less_config) if defined?(@less_config) && @less_config.is_a?(Hash) | ||
less |
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.
Add blank line before implicit return value
options[:load_paths] = options[:load_paths].is_a?(Array) ? options[:load_paths] : [] | ||
|
||
if (load_paths = options[:paths]) && (other_paths = other_options[:paths]) | ||
options[:load_paths] = options[:load_paths]+ other_paths + load_paths |
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.
Missing space around +
fetch_importer_class.fetch_all_dependencies(data, filename, less_options, css_options) | ||
end | ||
|
||
def merge_less_options(options, other_options) |
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.
So this is side-effectful on both options
and other_options
? I'd have expected only options
to suffer from side effects (like Hash#merge!
). Maybe some dup
is in order, or explain the rationale and/or behaviour in a comment.
options[:load_paths] = options[:load_paths]+ other_paths + load_paths | ||
end | ||
options[:load_paths] = options[:load_paths].concat(context.environment.paths) | ||
options |
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.
Remove extra spaceAdd blank line before implicit return value
|
||
def css_options | ||
css_keys = [:compress, :optimization, :silent, :color] | ||
Hash[less_options.to_enum.to_a.select{|k, _| css_keys.include? k}] |
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.
Add blank line before implicit return value
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.
spaces all around block's {
and }
else | ||
css | ||
end | ||
|
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.
Remove blank line
data = Sprockets::Less::Utils.read_file_binary(filename, options) | ||
new_data, dependencies = process_dependencies(data) | ||
|
||
css = less_engine(new_data, less_options, css_options) |
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.
Remove extra space before =
end | ||
else | ||
css | ||
end |
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.
Line 135 exit point is easily overlooked due to too much nesting. Turn if css.nil?
and if context.respond_to?(:metadata)
into guard clauses that return css
.
run | ||
end | ||
|
||
|
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.
Remove extra blank line
@filename = input[:filename] | ||
@source = input[:data] | ||
@context = input[:environment].context_class.new(input) | ||
run |
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.
Add blank line before implicit return value
engines = get_engines_from_attributes(context, attributes) | ||
preprocessors = get_context_preprocessors(context, content_type) | ||
additional_transformers = get_context_transformers(context, content_type, path) | ||
additional_transformers.reverse + preprocessors + engines.reverse |
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.
Add blank line before implicit return value
def content_type_of_path(context, path) | ||
attributes = context.environment.attributes_for(path) | ||
content_type = attributes.content_type | ||
[content_type, attributes] |
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.
Add blank line before implicit return value
def filtered_processor_classes | ||
classes = [Sprockets::Less::Utils.get_class_by_version('LessTemplate')] | ||
classes << Tilt::LessTemplate if defined?(Tilt::LessTemplate) | ||
classes |
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.
Add blank line before implicit return value
# Returns nil if the path is already to a partial. | ||
def partialize_path(path) | ||
return unless path.basename.to_s !~ /\A_/ | ||
Pathname.new path.to_s.sub(/([^\/]+)\Z/, '_\1') |
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.
Add blank line before implicit return value
relative_path = base_path.relative_path_from(root_path).join path | ||
paths.unshift(relative_path, partialize_path(relative_path)) | ||
end | ||
[paths, root_path] |
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.
Add blank line before implicit return value
|
||
# Find base_path's root | ||
paths, root_path = add_root_to_possible_files(context, base_path, path, paths) | ||
[paths.compact, root_path] |
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.
Add blank line before implicit return value
return found if context.asset_requirable?(found) | ||
end | ||
end | ||
nil |
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.
Use Enumerable#find
instead of each
Travis currently is failing , there seem to be some kind of caching problem, i am still trying to figure that out. Seems strange though, for other repositories i use same configuration, but for this repository it doesn't want to work . Need to spend more time investigating this problem |
context = less_options[:custom][:sprockets_context] | ||
(pathname = resolve(context, path, base_path)) || (return nil) | ||
context.depend_on pathname | ||
dependencies << pathname |
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.
Add blank line after to make the structure more clear
css = find_relative(import_path, pathname, less_options, css_options) | ||
data_to_parse.gsub!(/^\s*@import\s*['"]#{Regexp.escape(import_path)}['"]\s*;/, css) | ||
end | ||
end |
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.
Add blank line after to make the structure more clear
final_css | ||
end | ||
|
||
|
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.
Remove extra blank line
|
||
def font_path(source, options = {}) | ||
if options[:from_url] || (options.is_a?(Hash) && options.keys.size > 0) | ||
quote(sprockets_context.font_path(source, map_options(options))) |
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.
Indent by 2
@environment = environment | ||
end | ||
|
||
|
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.
Remove extra blank line
return if obj[:version] != version || obj[:sha] != sha | ||
obj[:obj] | ||
end | ||
|
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.
Remove blank line between end
obj = environment.send(:cache_get, "less/#{key}") | ||
return unless obj.is_a?(Hash) | ||
return if obj[:version] != version || obj[:sha] != sha | ||
obj[:obj] |
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.
Add blank line before implicit return value
Wow that was one hell of a review, nice piece of work, thanks a lot! I didn't find much questionable things :D Mostly that's about some style issues. So let me know if you can find anything on the Travis front, fix the nitpicks and we can finally get this merged! |
preprocessors = get_context_preprocessors(context, content_type) | ||
additional_transformers = get_context_transformers(context, content_type, path) | ||
postprocessors = get_context_postprocessors(context, content_type) | ||
engines.reverse + preprocessors + additional_transformers.reverse + postprocessors |
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.
Add blank line before implicit return value
content_type, attributes = content_type_of_path(context, path) | ||
processors = get_all_processors_for_evaluate(context, content_type, attributes, path) | ||
filter_all_processors(processors) | ||
evaluate_path_from_context(context, path, processors) |
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.
Add blank line before implicit return value
def get_context_transformers(context, content_type, path) | ||
available_transformers = context.environment.transformers[content_type] | ||
additional_transformers = available_transformers.key?(syntax_mime_type) ? available_transformers[syntax_mime_type] : [] | ||
additional_transformers.is_a?(Array) ? additional_transformers : [additional_transformers] |
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.
Add blank line before implicit return value
s.add_development_dependency 'test_construct', '~> 2.0' | ||
s.add_development_dependency 'rake' | ||
s.add_development_dependency 'appraisal', '~> 2.1', '>= 2.1' | ||
s.add_development_dependency 'rake', '>= 10.5', '>= 10.5' | ||
end |
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.
Add rubocop
as a version-softlocked development dependency:
s.add_development_dependency 'rubocop', '~> 0.46.0'
Hello.
I recently added support for Sprockets 3 for sprockets-sass gem ( here: petebrowne/sprockets-sass#38 ) and here petebrowne/sprockets-sass#39
After some discussion in the first pull request, we decided to use versionized classes, so that would be easier to maintain compatibility with other sprockets versions, so this uses same structure,
Basically the V2 classes will be used for sprockets 2.x
V3 ...for Sprockets 3.x
and V4...for Sprockets 4.x
The Registration class will automatically require the classes based on the version of sprockets loaded.
This pull request will also DROP Ruby 1.9 and also DROP TILT DEPENDENCY*
This pull request fixes some issues:
All tests are now passing for both 2.x and 3.x , except 6 tests related to the helpers we have for assets ( Which are broken because i honestly haven';t found a way to pass arguments to this methods, besides the first argument )
This seems to thow "Unrecognized input" when trying to parse it with the
Less::Parser
.I am going to still try and fix this, but i think this is not available for our
less.js
version (1.6.1) which is loaded by `less.rb`` (version 2.6.0 -- the last version)There is though LESS.js version 1.7.1, which has support for this, but the
less.js
repository hasn't been updated though :(Also there are some changes done for Sprockets 4.x but that is not yet complete. It does not fully support it yet.
But wanted to get some feedback on this, and maybe we can release the changes for sprockets 3.x and fix those other issues in other pull requests.
Let me know what you think. Have a nice day :)
P.S. If you have any idea how to pass those arguments to those helpers i would really appreciate.