active_assets 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  Gem::Specification.new do |s|
3
3
  s.name = "active_assets"
4
- s.version = '0.2.1'
4
+ s.version = '0.2.2'
5
5
  s.platform = Gem::Platform::RUBY
6
6
  s.authors = ["Sam Woodard"]
7
7
  s.email = ["sam@wildfireapp.com"]
@@ -9,5 +9,25 @@ module ActiveAssets
9
9
  autoload :Sprites
10
10
  autoload :SpriteStylesheet
11
11
  autoload :Runner
12
+
13
+ def self.load_engine_tasks(engine_class)
14
+ desc "Generate sprites"
15
+ task :sprites do
16
+ require 'rails'
17
+ require 'rails/active_sprites'
18
+
19
+ Rails.application ||= Class.new(Rails::Application)
20
+ Rails.application.extend Rails::ActiveSprites
21
+
22
+ engine = engine_class.new
23
+ sprite_path = File.join(engine.config.paths.config.paths.first, 'sprites.rb')
24
+
25
+ if File.exists?(sprite_path)
26
+ load sprite_path
27
+ Rails.application.sprites.generate!(engine)
28
+ end
29
+ end
30
+ end
31
+
12
32
  end
13
33
  end
@@ -1,4 +1,5 @@
1
1
  require 'rails'
2
+ require 'rails/railtie'
2
3
  require 'rails/active_sprites'
3
4
  require 'active_assets/active_sprites'
4
5
 
@@ -1,3 +1,5 @@
1
+ require 'action_controller'
2
+ require 'action_view'
1
3
  require 'rack/mount'
2
4
  require 'action_view'
3
5
  require 'rmagick'
@@ -15,9 +17,6 @@ module ActiveAssets
15
17
  DEFAULT_SPRITE = Image.new(0,0).freeze
16
18
 
17
19
  def initialize(sprites)
18
- @controller = ActionController::Base.new
19
- @context = AssetContext.new(Rails.application.config.action_controller, {}, @controller)
20
-
21
20
  @sprites = if ENV['SPRITE']
22
21
  sprites.select do |name, sprite|
23
22
  ENV['SPRITE'].split(',').map(&:compact).each do |sp|
@@ -32,7 +31,11 @@ module ActiveAssets
32
31
  end
33
32
  end
34
33
 
35
- def generate!(debug = ENV['DEBUG'])
34
+ def generate!(railtie = Rails.application, debug = ENV['DEBUG'])
35
+ p "Engine Class Name: #{railtie.class.name}" if debug
36
+
37
+ context = setup_context(railtie)
38
+
36
39
  @sprites.each do |sprite|
37
40
  next if sprite.sprite_pieces.empty?
38
41
  sprite_path = sanitize_asset_path(context.image_path(sprite.path))
@@ -45,7 +48,7 @@ module ActiveAssets
45
48
 
46
49
  begin
47
50
  sprite_piece_paths = sprite_pieces.map do |sp|
48
- File.join(Rails.application.config.paths.public.to_a.first, sanitize_asset_path(context.image_path(sp.path)))
51
+ File.join(railtie.config.paths.public.to_a.first, sanitize_asset_path(context.image_path(sp.path)))
49
52
  end
50
53
  image_list = ImageList.new(*sprite_piece_paths)
51
54
 
@@ -72,8 +75,8 @@ module ActiveAssets
72
75
  @sprite.strip!
73
76
 
74
77
  stylesheet = SpriteStylesheet.new(sprite_path, sprite_pieces)
75
- stylesheet.write File.join(Rails.application.config.paths.public.to_a.first, sprite_stylesheet_path)
76
- write File.join(Rails.application.config.paths.public.to_a.first, sprite_path), sprite.quality
78
+ stylesheet.write File.join(railtie.config.paths.public.to_a.first, sprite_stylesheet_path)
79
+ write File.join(railtie.config.paths.public.to_a.first, sprite_path), sprite.quality
77
80
  ensure
78
81
  finish
79
82
  end
@@ -81,10 +84,6 @@ module ActiveAssets
81
84
  end
82
85
 
83
86
  private
84
- def context
85
- @context
86
- end
87
-
88
87
  def write(path, quality = nil)
89
88
  FileUtils.mkdir_p(File.dirname(path))
90
89
  @sprite.write("#{File.extname(path)[1..-1]}:#{path}") do
@@ -101,6 +100,26 @@ module ActiveAssets
101
100
  path.split('?').first
102
101
  end
103
102
 
103
+ def setup_context(railtie)
104
+ unless railtie.config.respond_to?(:action_controller)
105
+ railtie.config.action_controller = ActiveSupport::OrderedOptions.new
106
+
107
+ paths = railtie.config.paths
108
+ options = railtie.config.action_controller
109
+
110
+ options.assets_dir ||= paths.public.to_a.first
111
+ options.javascripts_dir ||= paths.public.javascripts.to_a.first
112
+ options.stylesheets_dir ||= paths.public.stylesheets.to_a.first
113
+
114
+ ActiveSupport.on_load(:action_controller) do
115
+ options.each { |k,v| send("#{k}=", v) }
116
+ end
117
+ end
118
+
119
+ controller = ActionController::Base.new
120
+ AssetContext.new(railtie.config.action_controller, {}, controller)
121
+ end
122
+
104
123
  end
105
124
  end
106
125
  end
@@ -43,10 +43,10 @@ module ActiveAssets
43
43
  @sprites.clear
44
44
  end
45
45
 
46
- def generate!
46
+ def generate!(railtie = Rails.application)
47
47
  begin
48
48
  require 'rmagick'
49
- Runner.new(@sprites).generate!
49
+ Runner.new(@sprites).generate!(railtie)
50
50
  rescue LoadError
51
51
  end
52
52
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_assets
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 1
10
- version: 0.2.1
9
+ - 2
10
+ version: 0.2.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sam Woodard