Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #27 from lotus/simplify-internals
Simplify internals
  • Loading branch information
jodosha committed Dec 11, 2015
2 parents 39dee68 + 394909f commit 984b424
Show file tree
Hide file tree
Showing 21 changed files with 296 additions and 460 deletions.
6 changes: 4 additions & 2 deletions Gemfile
Expand Up @@ -10,7 +10,9 @@ end
gem 'simplecov', require: false
gem 'coveralls', require: false

gem 'lotus-utils', '~> 0.6', github: 'lotus/utils', branch: '0.6.x'
gem 'lotus-view', '~> 0.5', github: 'lotus/view', branch: '0.5.x'
gem 'lotus-utils', '~> 0.6', github: 'lotus/utils', branch: '0.6.x'
gem 'lotus-helpers', '~> 0.2', github: 'lotus/helpers', branch: '0.2.x'
gem 'lotus-view', '~> 0.5', github: 'lotus/view', branch: '0.5.x'

gem 'lotus-emberjs', path: 'test/fixtures/lotus-emberjs', require: false
gem 'lotus-compass', path: 'test/fixtures/lotus-compass', require: false
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -177,7 +177,7 @@ When from a template you do:
`Lotus::Assets` looks at the defined sources and **lazily copies** those files
under `public/assets` (by default), before the markup is generated.

Your destination directory will have the following structure.
Your public directory will have the following structure.

```shell
% tree public
Expand All @@ -192,7 +192,7 @@ public/
**Please remember that sources are recursively looked up in order of declaration.**

If in the example above we had a `jquery.js` under `app/assets/javascripts/**/*.js`
that file would be copied into the destination folder instead of the one under
that file would be copied into the public directory instead of the one under
`vendor/jquery`. The reason is because we declared `app/assets/javascripts` first.

#### Preprocessors
Expand Down Expand Up @@ -228,7 +228,7 @@ When from a template you do:
<%= stylesheet 'reset', 'main' %>
```

Your destination directory will have the following structure.
Your public directory will have the following structure.

```shell
% tree public
Expand Down
4 changes: 2 additions & 2 deletions lib/lotus/assets/bundler.rb
Expand Up @@ -32,7 +32,7 @@ def run
private

def assets
Dir.glob("#{ destination }/**/*")
Dir.glob("#{ destination }#{ ::File::SEPARATOR }**#{ ::File::SEPARATOR }*")
end

def compress(asset)
Expand Down Expand Up @@ -81,7 +81,7 @@ def _set_permissions(path)
end

def destination
@configuration.destination
@configuration.public_directory
end
end
end
Expand Down
34 changes: 19 additions & 15 deletions lib/lotus/assets/compiler.rb
Expand Up @@ -17,26 +17,27 @@ def initialize(source)
class Compiler
DEFAULT_PERMISSIONS = 0644

COMPILE_PATTERN = '*.*.*'.freeze # Example hello.js.es6

SASS_CACHE_LOCATION = Pathname(Lotus.respond_to?(:root) ?
Lotus.root : Dir.pwd).join('tmp', 'sass-cache')


def self.compile(configuration, type, name)
def self.compile(configuration, name)
return unless configuration.compile

require 'tilt'
require 'lotus/assets/cache'
new(configuration, type, name).compile
new(configuration, name).compile
end

def self.cache
@@cache ||= Assets::Cache.new
end

def initialize(configuration, type, name)
def initialize(configuration, name)
@configuration = configuration
@definition = @configuration.asset(type)
@name = name + @definition.ext
@name = Pathname.new(name)
end

def compile
Expand All @@ -54,21 +55,24 @@ def compile

private
def source
@source ||= @configuration.find(@name)
@source ||= begin
@name.absolute? ? @name :
@configuration.find(@name)
end
end

# FIXME this has a really poor perf
# TODO Move this responsibility to @definition.relative_path
def destination
@destination ||= begin
Pathname.new(Utils::PathPrefix.new(@configuration.destination).join(@configuration.prefix, @definition.relative_path(@name))).tap do |dest|
dest.dirname.mkpath
end
end
@destination ||= @configuration.destination_directory.join(basename)
end

def basename
result = ::File.basename(@name)
result.scan(/\A[[[:alnum:]][\-\_]]*\.[[\w]]*/).first || result
end

def exist?
!source.nil?
!source.nil? &&
source.exist?
end

def fresh?
Expand All @@ -77,7 +81,7 @@ def fresh?
end

def compile?
source.extname != @definition.ext
::File.fnmatch(COMPILE_PATTERN, source.to_s)
end

def compile!
Expand Down
70 changes: 0 additions & 70 deletions lib/lotus/assets/config/asset_type.rb

This file was deleted.

56 changes: 0 additions & 56 deletions lib/lotus/assets/config/asset_types.rb

This file was deleted.

2 changes: 1 addition & 1 deletion lib/lotus/assets/config/sources.rb
Expand Up @@ -32,7 +32,7 @@ def find(filename)
def files(name = nil)
result = []

Dir.glob(map {|source| "#{ source }/**/#{ name }*"}).each do |file|
Dir.glob(map {|source| "#{ source }#{ ::File::SEPARATOR }**#{ ::File::SEPARATOR }#{ name }*"}).each do |file|
next if ::File.directory?(file) || ::File.basename(file).match(/\A\_/)
result << file
end
Expand Down

0 comments on commit 984b424

Please sign in to comment.