middleman-jammit 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,6 +9,10 @@ Use Jammit in Middleman - merge multiple javascripts/stylesheets into one
9
9
  gem install middleman-jammit -v 0.0.2 # for middleman 1.2.7
10
10
  gem install middleman-jammit -v 0.2.0 # for middleman 2.x
11
11
 
12
+ For middleman 3.x you can add it to your Gemfile:
13
+
14
+ gem 'middleman-jammit'
15
+
12
16
  2. Create your project
13
17
 
14
18
  middleman init your-middleman-project
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- require "middleman"
2
+ require "middleman-core"
3
3
  require "thor"
4
4
  require "thor/group"
5
5
 
@@ -9,9 +9,9 @@ module Middleman::Jammit
9
9
 
10
10
  class_option :package_path, :default => "assets", :desc => 'The path to the asset files'
11
11
 
12
- class_option :build_dir, :default => Middleman.server.build_dir, :desc => 'Your build dir'
13
- class_option :css_dir, :default => Middleman.server.css_dir, :desc => 'The path to the css files'
14
- class_option :js_dir, :default => Middleman.server.js_dir, :desc => 'The path to the javascript files'
12
+ class_option :build_dir, :default => Middleman::Application.server.inst.build_dir, :desc => 'Your build dir'
13
+ class_option :css_dir, :default => Middleman::Application.server.inst.css_dir, :desc => 'The path to the css files'
14
+ class_option :js_dir, :default => Middleman::Application.server.inst.js_dir, :desc => 'The path to the javascript files'
15
15
 
16
16
 
17
17
  def self.source_root
@@ -19,11 +19,11 @@ module Middleman::Jammit
19
19
  end
20
20
 
21
21
  def create_jammit_config
22
- config_dir = File.join(Middleman.server.root, "config")
22
+ config_dir = File.join(Middleman::Application.server.inst.root, "config")
23
23
  empty_directory config_dir
24
24
  template "assets.yml.tt", File.join(config_dir, "assets.yml")
25
- prepend_file File.join(Middleman.server.root, "config.rb") do
26
- ['require "middleman-jammit"', 'activate :jammit', "", ""].join("\n")
25
+ prepend_file File.join(Middleman::Application.server.inst.root, "config.rb") do
26
+ ['activate :jammit', "", ""].join("\n")
27
27
  end
28
28
  end
29
29
 
@@ -1,18 +1,21 @@
1
1
  require "jammit"
2
- require "middleman/builder"
2
+ require "middleman-core"
3
3
 
4
4
  module Middleman
5
- module Features
6
- module Jammit
5
+ module Jammit
7
6
 
8
- class << self
9
- def registered(app)
10
- full_build_dir = File.join(Middleman.server.root, Middleman.server.build_dir)
7
+ class << self
8
+ include Thor::Actions
9
+ def registered(app)
10
+ app.send :include, InstanceMethods
11
11
 
12
- FileUtils.mkdir_p File.join(full_build_dir, Middleman.server.js_dir)
13
- FileUtils.mkdir_p File.join(full_build_dir, Middleman.server.css_dir)
12
+ app.after_configuration do
13
+ full_build_dir = File.join(root, build_dir)
14
14
 
15
- jammit_config_file = File.join(Middleman.server.root, 'config', 'assets.yml')
15
+ FileUtils.mkdir_p File.join(full_build_dir, js_dir)
16
+ FileUtils.mkdir_p File.join(full_build_dir, css_dir)
17
+
18
+ jammit_config_file = File.join(root, 'config', 'assets.yml')
16
19
  raise ConfigurationNotFound, "could not find \"#{jammit_config_file}\" " unless File.exists?(jammit_config_file)
17
20
  jammit_conf = YAML.load(ERB.new(File.read(jammit_config_file)).result)
18
21
 
@@ -20,71 +23,73 @@ module Middleman
20
23
  touch_asset_files jammit_conf['stylesheets']
21
24
 
22
25
  ::Jammit.load_configuration(jammit_config_file)
26
+ end
23
27
 
24
- Middleman::Builder.after_run "jammit" do
25
- full_package_path = File.join(full_build_dir, ::Jammit.package_path)
26
- ::Jammit.packager.precache_all(full_package_path, Middleman.server.root)
27
- say_status "Jammit", "build/assets"
28
- end
28
+ app.after_build "jammit" do |build|
29
+ full_package_path = File.join(File.join(root, build_dir), ::Jammit.package_path)
30
+ ::Jammit.packager.precache_all(full_package_path, root)
31
+ build.say_status "Jammit", "build/assets"
32
+ end
29
33
 
30
- app.helpers Jammit::Helpers
34
+ app.helpers Helpers
31
35
 
32
- end
33
- alias :included :registered
34
-
35
- protected
36
- def touch_asset_files(asset_files)
37
- if asset_files.present?
38
- asset_files.each do |name, files|
39
- files.each do |f|
40
- next if f["*"].present?
41
- FileUtils.touch File.join(Middleman.server.root, f)
42
- end
43
- end
36
+ end
37
+ alias :included :registered
38
+
39
+ end
40
+
41
+ module InstanceMethods
42
+ def touch_asset_files(asset_files)
43
+ if asset_files.present?
44
+ asset_files.each do |name, files|
45
+ files.each do |f|
46
+ next if f["*"].present?
47
+ FileUtils.touch File.join(root, f)
44
48
  end
45
49
  end
46
-
50
+ end
47
51
  end
52
+ end
48
53
 
49
- module Helpers
54
+ module Helpers
50
55
 
51
- def include_javascripts(*packages)
52
- generate_asset_tags(packages, :js)
53
- end
56
+ def include_javascripts(*packages)
57
+ generate_asset_tags(packages, :js)
58
+ end
54
59
 
55
- def include_stylesheets(*packages)
56
- generate_asset_tags(packages, :css)
57
- end
60
+ def include_stylesheets(*packages)
61
+ generate_asset_tags(packages, :css)
62
+ end
58
63
 
59
- protected
60
- def generate_asset_tags(packages, type)
61
- packages.map do |pack|
62
- if ENV['MM_ENV'] == "build"
63
- url = asset_url(::Jammit.asset_url(pack, type.to_sym))
64
+ protected
65
+ def generate_asset_tags(packages, type)
66
+ packages.map do |pack|
67
+ if ENV['MM_ENV'] == "build"
68
+ url = asset_url(::Jammit.asset_url(pack, type.to_sym))
69
+ generate_tag(type, url)
70
+ else
71
+ ::Jammit.packager.individual_urls(pack.to_sym, type.to_sym).map do |file|
72
+ url = file.gsub(%r(^.*build/), '/')
64
73
  generate_tag(type, url)
65
- else
66
- ::Jammit.packager.individual_urls(pack.to_sym, type.to_sym).map do |file|
67
- url = file.gsub(%r(^.*build/), '/')
68
- generate_tag(type, url)
69
- end
70
74
  end
71
- end.join("\n")
72
- end
73
-
74
- def generate_tag(type, url)
75
- self.method("#{type.to_s}_tag").call(url)
76
- end
75
+ end
76
+ end.join("\n")
77
+ end
77
78
 
78
- def js_tag(url)
79
- javascript_include_tag url
80
- end
79
+ def generate_tag(type, url)
80
+ self.method("#{type.to_s}_tag").call(url)
81
+ end
81
82
 
82
- def css_tag(url)
83
- stylesheet_link_tag url
84
- end
83
+ def js_tag(url)
84
+ javascript_include_tag url
85
+ end
85
86
 
86
- end
87
+ def css_tag(url)
88
+ stylesheet_link_tag url
89
+ end
87
90
 
88
91
  end
92
+
89
93
  end
90
94
  end
95
+ ::Middleman::Extensions.register(:jammit, Middleman::Jammit)
@@ -1,5 +1,5 @@
1
1
  module Middleman
2
2
  module Jammit
3
- VERSION = "0.2.0"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
15
15
  s.rubyforge_project = "middleman-jammit"
16
16
 
17
17
  s.add_dependency "jammit", "~> 0.6"
18
- s.add_dependency "middleman", "> 1.2.7"
18
+ s.add_dependency "middleman", ">= 3.0.0"
19
19
 
20
20
  s.files = `git ls-files`.split("\n")
21
21
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: middleman-jammit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-06 00:00:00.000000000Z
12
+ date: 2012-07-21 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: jammit
16
- requirement: &70238914407440 !ruby/object:Gem::Requirement
16
+ requirement: &70140587370860 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,18 +21,18 @@ dependencies:
21
21
  version: '0.6'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70238914407440
24
+ version_requirements: *70140587370860
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: middleman
27
- requirement: &70238914406940 !ruby/object:Gem::Requirement
27
+ requirement: &70140587370360 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
- - - ! '>'
30
+ - - ! '>='
31
31
  - !ruby/object:Gem::Version
32
- version: 1.2.7
32
+ version: 3.0.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70238914406940
35
+ version_requirements: *70140587370360
36
36
  description: Use Jammit in Middleman - merge multiple javascripts/stylesheets into
37
37
  one
38
38
  email: