Skip to content

Commit

Permalink
Merge pull request #23 from janosrusiczki/rubocop-fixes
Browse files Browse the repository at this point in the history
Rubocop fixes.
  • Loading branch information
janosrusiczki authored Dec 3, 2017
2 parents 485772a + b5f6f34 commit 9762fe4
Show file tree
Hide file tree
Showing 17 changed files with 192 additions and 181 deletions.
2 changes: 0 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
inherit_from: .rubocop_todo.yml

Encoding:
EnforcedStyle: when_needed
14 changes: 5 additions & 9 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 1
# Configuration parameters: CountComments.
ClassLength:
Max: 169

# Offense count: 34
Documentation:
Enabled: false
Expand All @@ -24,10 +19,6 @@ MethodLength:
ParameterLists:
Max: 7

# Offense count: 1
RegexpLiteral:
MaxSlashes: 2

# Offense count: 7
# Cop supports --auto-correct.
RescueException:
Expand All @@ -44,3 +35,8 @@ SignalException:
# Configuration parameters: ExactNameMatch, AllowPredicates, AllowDSLWriters, Whitelist.
TrivialAccessors:
Enabled: false

# This is not the nicest, but it works
Metrics/BlockLength:
ExcludedMethods: ['describe', 'context']

2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: ruby

rvm:
- 2.1.0
- 2.2

script:
- bundle exec rake test
Expand Down
12 changes: 6 additions & 6 deletions japr.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@ Gem::Specification.new do |s|
s.name = 'japr'
s.version = JAPR::VERSION
s.date = Time.now
s.summary = <<-EOF
s.summary = <<-SUMMARY
A powerful asset pipeline for Jekyll that bundles, converts, and minifies
CSS and JavaScript assets.
EOF
s.description = <<-EOF
SUMMARY
s.description = <<-DESCRIPTION
Jekyll Asset Pipeline reborn adds asset preprocessing (CoffeeScript, Sass,
Less, ERB, etc.) and asset compression / minification / gzip (Yahoo YUI
Compressor, Google Closure Compiler, etc.) to Jekyll.'
EOF
DESCRIPTION
s.authors = ['Matt Hodan']
s.email = '[email protected]'
s.homepage = 'https://github.com/kitsched/japr'
s.license = 'MIT'
s.required_ruby_version = '>= 2.1.0'
s.required_ruby_version = '>= 2.2.0'

# Runtime dependencies
s.add_runtime_dependency 'jekyll', '~> 3.5'
s.add_runtime_dependency 'liquid', '~> 4.0'

# Development dependencies
s.add_development_dependency 'rake', '~> 10.0'
s.add_development_dependency 'minitest', '~> 5.2'
s.add_development_dependency 'rake', '~> 10.0'

# Files
s.files = Dir['lib/**/*.rb', 'LICENSE', 'README.md'].to_a
Expand Down
2 changes: 1 addition & 1 deletion lib/japr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@ module JAPR
'bundle' => true,
'compress' => true,
'gzip' => false
}
}.freeze
end
7 changes: 7 additions & 0 deletions lib/japr/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ def self.filetype
''
end

# Finds a converter class based on a filename
def self.klass(filename)
JAPR::Converter.subclasses.select do |c|
c.filetype == File.extname(filename).downcase
end.last
end

# Logic to convert assets
#
# Available instance variables:
Expand Down
49 changes: 27 additions & 22 deletions lib/japr/extensions/liquid/liquid_block_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,35 @@ def tag_name

def render(context)
site = context.registers[:site]
config = site.config['asset_pipeline'] || {}
config = site.config.fetch('asset_pipeline', {})

# Run Jekyll Asset Pipeline
pipeline, cached = Pipeline.run(nodelist.first, @markup.strip,
site.source, site.dest,
self.class.tag_name,
self.class.output_type, config)

if pipeline.is_a?(Pipeline)
# Prevent Jekyll from cleaning up saved assets if new pipeline
pipeline.assets.each do |asset|
config = JAPR::DEFAULTS.merge(config)
staging_path = File.expand_path(File.join(site.source,
config['staging_path']))
site.static_files << Jekyll::StaticFile.new(site, staging_path,
asset.output_path,
asset.filename)
end unless cached

# Return HTML tag pointing to asset
return pipeline.html
else
# Return nothing
return nil
pipeline, cached = run_pipeline(site, config)

return nil unless pipeline.is_a?(Pipeline)

# Prevent Jekyll from cleaning up saved assets if new pipeline
preserve_assets(site, config, pipeline) unless cached

# Return HTML tag pointing to asset
pipeline.html
end

private

def run_pipeline(site, config)
Pipeline.run(nodelist.first, @markup.strip, site.source, site.dest,
self.class.tag_name, self.class.output_type, config)
end

def preserve_assets(site, config, pipeline)
pipeline.assets.each do |asset|
config = JAPR::DEFAULTS.merge(config)
staging_path = File.expand_path(File.join(site.source,
config['staging_path']))
site.static_files << Jekyll::StaticFile.new(site, staging_path,
asset.output_path,
asset.filename)
end
end
end
Expand Down
Loading

0 comments on commit 9762fe4

Please sign in to comment.