Skip to content

Commit

Permalink
Merge pull request #5 from geniou/master
Browse files Browse the repository at this point in the history
Fix specs and minor cleanup.
  • Loading branch information
janosrusiczki committed Mar 7, 2014
2 parents a43574a + f6ec541 commit ea8ffa8
Show file tree
Hide file tree
Showing 14 changed files with 97 additions and 99 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
language: ruby
rvm:
- 1.9.3
- 2.0.0
- 2.1.0

install:
- bundle install
- rake test || exit 1
script: bundle exec rake test

2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'rake'
require 'rake/testtask'

task :default => [:test]
task default: [:test]

Rake::TestTask.new(:test) do |test|
test.libs << 'spec'
Expand Down
4 changes: 2 additions & 2 deletions japr.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ Gem::Specification.new do |s|
s.email = 'japr@clicktrackheart.com'
s.homepage = 'https://github.com/kitsched/japr'
s.license = 'MIT'
s.required_ruby_version = '>= 1.9.3'
s.required_ruby_version = '>= 1.9.3'

# Runtime dependencies
s.add_runtime_dependency 'jekyll', '~> 1.1'
s.add_runtime_dependency 'liquid', '~> 2.4'
Expand Down
2 changes: 1 addition & 1 deletion lib/japr/compressor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Compressor

def initialize(content)
@content = content
@compressed = self.compress
@compressed = compress
end

# Returns compressed content
Expand Down
2 changes: 1 addition & 1 deletion lib/japr/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Converter
def initialize(asset)
@content = asset.content
@type = File.extname(asset.filename).downcase
@converted = self.convert
@converted = convert
end

def converted
Expand Down
6 changes: 3 additions & 3 deletions lib/japr/extensions/jekyll/site_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def self.included(base)
# Override Jekyll::Site#cleanup
define_method(:cleanup) do
# Run the Jekyll::Site#cleanup method
original_return_val = old_cleanup_method.bind(self).call()
original_return_val = old_cleanup_method.bind(self).call

# Clear Jekyll Asset Pipeline cache
Pipeline.clear_cache
Expand All @@ -22,11 +22,11 @@ def self.included(base)
# Override Jekyll::Site#write
define_method(:write) do
# Run the Jekyll::Site#write method
original_return_value = old_write_method.bind(self).call()
original_return_value = old_write_method.bind(self).call

# Clear Jekyll Asset Pipeline staged assets
config = self.config['asset_pipeline'] || {}
Pipeline.remove_staged_assets(self.source, config)
Pipeline.remove_staged_assets(source, config)

original_return_value
end
Expand Down
9 changes: 6 additions & 3 deletions lib/japr/extensions/liquid/liquid_block_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@ def render(context)
config = site.config['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)
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)
asset.output_path,
asset.filename)
end unless cached

# Return HTML tag pointing to asset
Expand Down
26 changes: 11 additions & 15 deletions lib/japr/pipeline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class << self
def hash(source, manifest, options = {})
options = DEFAULTS.merge(options)
begin
Digest::MD5.hexdigest(YAML::load(manifest).map! do |path|
Digest::MD5.hexdigest(YAML.load(manifest).map! do |path|
"#{path}#{File.mtime(File.join(source, path)).to_i}"
end.join.concat(options.to_s))
rescue Exception => e
Expand All @@ -20,15 +20,15 @@ def run(manifest, prefix, source, destination, tag, type, config)
hash = hash(source, manifest, config)

# Check if pipeline has been cached
if cache.has_key?(hash)
if cache.key?(hash)
# Return cached pipeline and cached status
return cache[hash], true
else
begin
puts "Processing '#{tag}' manifest '#{prefix}'"

# Create and process new pipeline
pipeline = self.new(manifest, prefix, source, destination, type, config)
pipeline = new(manifest, prefix, source, destination, type, config)
pipeline.assets.each do |asset|
puts "Saved '#{asset.filename}' to '#{destination}/#{asset.output_path}'"
end
Expand Down Expand Up @@ -60,16 +60,14 @@ def clear_cache

# Remove staged assets
def remove_staged_assets(source, config)
begin
config = DEFAULTS.merge(config)
staging_path = File.join(source, config['staging_path'])
FileUtils.rm_rf(staging_path)
config = DEFAULTS.merge(config)
staging_path = File.join(source, config['staging_path'])
FileUtils.rm_rf(staging_path)
rescue Exception => e
puts "Failed to remove staged assets."

# Re-raise the exception
raise e
end
end

# Add prefix to output
Expand Down Expand Up @@ -107,16 +105,14 @@ def process

# Collect assets based on manifest
def collect
begin
@assets = YAML::load(@manifest).map! do |path|
File.open(File.join(@source, path)) do |file|
JAPR::Asset.new(file.read, File.basename(path))
end
@assets = YAML.load(@manifest).map! do |path|
File.open(File.join(@source, path)) do |file|
JAPR::Asset.new(file.read, File.basename(path))
end
end
rescue Exception => e
puts "Asset Pipeline: Failed to load assets from provided manifest."
raise e
end
end

# Convert assets based on the file extension if converter is defined
Expand Down Expand Up @@ -197,7 +193,7 @@ def save

@assets.each do |asset|
directory = File.join(@source, staging_path, output_path)
FileUtils::mkpath(directory) unless File.directory?(directory)
FileUtils.mkpath(directory) unless File.directory?(directory)

begin
# Save file to disk
Expand Down
2 changes: 1 addition & 1 deletion spec/extensions/jekyll/site_extensions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def write

it "clears JAPR::Cache when Jekyll::Site#cleanup is called" do
subject # Setup subject
Pipeline.cache.has_key?('foo').must_equal(false)
Pipeline.cache.key?('foo').must_equal(false)
end

it "returns the same value as the original Jekyll::Site#cleanup method" do
Expand Down
4 changes: 2 additions & 2 deletions spec/extensions/liquid/liquid_block_extensions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def self.output_type

let(:context) do
context = MiniTest::Mock.new
context.expect(:registers, { site: site })
context.expect(:registers, site: site)
context
end

Expand Down Expand Up @@ -82,7 +82,7 @@ def self.output_type

let(:context) do
context = MiniTest::Mock.new
context.expect(:registers, { site: site })
context.expect(:registers, site: site)
context
end

Expand Down
2 changes: 1 addition & 1 deletion spec/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ def clear_temp_path

# Let us use 'context' in specs
class << self
alias :context :describe
alias_method :context, :describe
end
end
Loading

0 comments on commit ea8ffa8

Please sign in to comment.