dominate 0.8.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8c095094c79fc311758877e11f42dfb49841e822
4
- data.tar.gz: 49235cf08d8ce3dd86aa3f421147efc4ce07ccfb
3
+ metadata.gz: 864743b37dfcebd9f526d7bacbf8b343d9ccafef
4
+ data.tar.gz: cad1bd5848f42ff269c02cd0f340a82775f9367d
5
5
  SHA512:
6
- metadata.gz: 1b149de53b4a44ba8c2b3c15394a3ea889a7711d46a23ed80a621c1612987bf5e2ca10a936a771b9f5603bb72dc7d0593188ccfd2f783ab22097fab5aaee2f64
7
- data.tar.gz: 10cd56e3438dafd5e9cb6806480302bdd53dcb555baa7696e13d1917ffc7db4adcf648588c9bfeee3233c2c4b5fceea4969d4055a32a0c70a9990bdb49a4a75b
6
+ metadata.gz: 4b96cb07e58de04d6ea195c0cbff175cee36ffcac3291ada395784014c50c3ea3a1a5d60f2ef2fdd9ca912b0c843f9ccae0bbb7d350cbd9a5b34e1cc87cf5bd0
7
+ data.tar.gz: 15a5ffa800ad2d0599fcd5ddd9074eb03204ae84d582242ee53061f662349137faf1a3e6e933d8435e7eadf9e89b57022c85935679b1709d8a207c227a9575b1
data/dominate.gemspec CHANGED
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.add_dependency "tilt"
23
23
  spec.add_dependency "nokogiri-styles"
24
24
  spec.add_dependency "eventable"
25
+ spec.add_dependency "mab", "~> 0.0.3"
25
26
 
26
27
  spec.add_development_dependency "bundler", "~> 1.3"
27
28
  spec.add_development_dependency "rake"
@@ -3,8 +3,6 @@ require 'rack/mime'
3
3
  module Dominate
4
4
  module Assets
5
5
  class Middleware
6
- STATIC_TYPES = %w(html js css eot woff ttf svg)
7
-
8
6
  attr_reader :app, :env, :res
9
7
 
10
8
  def initialize(app)
@@ -58,10 +56,12 @@ module Dominate
58
56
  end
59
57
 
60
58
  def name
61
- cleaned = path.gsub(/\.#{ext}$/, '')
62
- cleaned = cleaned.gsub(/^#{Dominate.config.asset_url}\//, '')
63
- cleaned = cleaned.gsub(/^#{type}\//, '')
64
- cleaned
59
+ @name ||= begin
60
+ cleaned = path.gsub(/\.#{ext}$/, '')
61
+ cleaned = cleaned.gsub(/^#{Dominate.config.asset_url}\//, '')
62
+ cleaned = cleaned.gsub(/^#{type}\//, '')
63
+ cleaned
64
+ end
65
65
  end
66
66
 
67
67
  def ext
@@ -73,22 +73,31 @@ module Dominate
73
73
  end
74
74
 
75
75
  def render_assets
76
- if name == 'all'
77
- res.write render_all_files
78
- else
79
- res.write render_single_file
80
- end
81
-
82
76
  case type
83
77
  when 'css', 'stylesheet', 'stylesheets'
84
- content_type = 'text/css'
78
+ content_type = 'text/css; charset=utf-8'
85
79
  when 'js', 'javascript', 'javascripts'
86
- content_type = 'text/javascript'
80
+ content_type = 'text/javascript; charset=utf-8'
87
81
  else
88
82
  content_type = Rack::Mime.mime_type ext
89
83
  end
90
84
 
91
- res.headers["Content-Type"] = content_type
85
+ res.headers.merge!({
86
+ "Content-Type" => content_type,
87
+ "Cache-Control" => 'public, max-age=2592000, no-transform',
88
+ 'Connection' => 'keep-alive',
89
+ 'Age' => '25637',
90
+ 'Strict-Transport-Security' => 'max-age=31536000'
91
+ })
92
+
93
+ if name == "all-#{sha}"
94
+ @name = 'dominate-compiled'
95
+ res.write render_single_file
96
+ elsif name == 'all'
97
+ res.write render_all_files
98
+ else
99
+ res.write render_single_file
100
+ end
92
101
 
93
102
  res.finish
94
103
  end
@@ -99,7 +108,7 @@ module Dominate
99
108
  path = "#{Dominate.config.asset_path}/#{type}"
100
109
 
101
110
  files.each do |file|
102
- content += load_file "#{path}/#{file}"
111
+ content += Dominate::HTML.load_file "#{path}/#{file}"
103
112
  end
104
113
 
105
114
  content
@@ -107,17 +116,11 @@ module Dominate
107
116
 
108
117
  def render_single_file
109
118
  path = "#{Dominate.config.asset_path}/#{type}"
110
- load_file "#{path}/#{name}.#{ext}"
119
+ Dominate::HTML.load_file "#{path}/#{name}.#{ext}"
111
120
  end
112
121
 
113
- def load_file path
114
- ext = path[/\.[^.]*$/][1..-1]
115
-
116
- if STATIC_TYPES.include? ext
117
- File.read path
118
- else
119
- Dominate::HTML.load_file path
120
- end
122
+ def sha
123
+ Thread.current[:_sha] ||= `git rev-parse HEAD`.strip
121
124
  end
122
125
  end
123
126
  end
@@ -1,6 +1,72 @@
1
+ require 'dominate/mab'
2
+
1
3
  module Dominate
2
4
  module Assets
3
5
  autoload :Middleware, 'dominate/assets/middleware'
4
6
  autoload :Render, 'dominate/assets/render'
7
+
8
+ def self.setup app
9
+ app.use Middleware
10
+ app.plugin Render
11
+ end
12
+
13
+ def css_assets options = {}
14
+ options = {
15
+ 'data-turbolinks-track' => 'true',
16
+ rel: 'stylesheet',
17
+ type: 'text/css',
18
+ media: 'all'
19
+ }.merge options
20
+
21
+ url = Dominate.config.asset_url
22
+
23
+ if Dominate.config.assets_compiled
24
+ options[:href] = "#{url}/css/all-#{sha}.css"
25
+ else
26
+ options[:href] = "#{url}/css/all.css"
27
+ end
28
+
29
+ mab { link options }
30
+ end
31
+
32
+ def js_assets options = {}
33
+ options = {
34
+ 'data-turbolinks-track' => 'true',
35
+ }.merge options
36
+
37
+ url = Dominate.config.asset_url
38
+
39
+ if Dominate.config.assets_compiled
40
+ options[:src] = "#{url}/js/all-#{sha}.js"
41
+ else
42
+ options[:src] = "#{url}/js/all.js"
43
+ end
44
+
45
+ mab { script options }
46
+ end
47
+
48
+ def self.compile
49
+ Dominate.config.assets.to_h.each do |type, assets|
50
+ content = ''
51
+
52
+ if assets.length > 0
53
+ type_path = "#{Dominate.config.asset_path}/#{Dominate.config[:"asset_#{type}_folder"]}"
54
+ assets.each do |file|
55
+ path = "#{type_path}/#{file}"
56
+ content += Dominate::HTML.load_file path
57
+ end
58
+ tmp_path = "#{type_path}/tmp.dominate-compiled.#{type}"
59
+ File.write "#{type_path}/dominate-compiled.#{type}", content
60
+ # system "minify #{tmp_path} > #{type_path}/dominate-compiled.#{type}"
61
+ # File.delete tmp_path
62
+ end
63
+ end
64
+ end
65
+
66
+ private
67
+
68
+ def sha
69
+ Thread.current[:_sha] ||= `git rev-parse HEAD`.strip
70
+ end
5
71
  end
6
72
  end
data/lib/dominate/html.rb CHANGED
@@ -1,8 +1,12 @@
1
+ require 'tilt/template'
2
+
1
3
  module Dominate
2
4
  module HTML
3
5
  extend self
4
6
 
5
- VIEW_TYPES = %w(html slim haml erb md markdown mkd mab)
7
+ STATIC_TYPES = %w(html js css eot woff ttf svg)
8
+ VIEW_TYPES = %w(html slim haml erb md markdown mkd mab)
9
+
6
10
 
7
11
  def file file, instance = false, config = {}
8
12
  c = (Dominate.config.to_h.merge config).to_deep_ostruct
@@ -27,11 +31,20 @@ module Dominate
27
31
  end
28
32
 
29
33
  def load_file path, c = {}, instance = self
34
+ c[:moo] = 'cow'
30
35
  html = _cache.fetch(path) {
31
36
  template = false
32
37
 
33
- if path[/\..*$/] && File.file?(path)
34
- template = Tilt.new path, 1, outvar: '@_output'
38
+ ext = path[/\.[^.]*$/][1..-1]
39
+
40
+ if ext && File.file?(path)
41
+ if STATIC_TYPES.include? ext
42
+ template = Tilt::PlainTemplate.new nil, 1, outvar: '@_output', default_encoding: 'UTF-8' do |t|
43
+ File.read(path)
44
+ end
45
+ else
46
+ template = Tilt.new path, 1, outvar: '@_output'
47
+ end
35
48
  else
36
49
  VIEW_TYPES.each do |type|
37
50
  f = "#{path}.#{type}"
@@ -0,0 +1,5 @@
1
+ require 'mab'
2
+
3
+ def mab(&blk)
4
+ Mab::Builder.new({}, self, &blk).to_s
5
+ end
@@ -1,3 +1,3 @@
1
1
  module Dominate
2
- VERSION = "0.8.1"
2
+ VERSION = "0.9.0"
3
3
  end
data/lib/dominate.rb CHANGED
@@ -40,8 +40,11 @@ module Dominate
40
40
  js: {},
41
41
  css: {}
42
42
  }),
43
- asset_url: '/assets',
44
- asset_path: './assets'
43
+ asset_url: '/assets',
44
+ asset_path: './assets',
45
+ asset_js_folder: 'js',
46
+ asset_css_folder: 'css',
47
+ assets_compiled: false
45
48
  })
46
49
  end
47
50
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dominate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - cj
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-09 00:00:00.000000000 Z
11
+ date: 2014-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mab
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 0.0.3
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 0.0.3
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: bundler
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -187,6 +201,7 @@ files:
187
201
  - lib/dominate/html.rb
188
202
  - lib/dominate/inflectors.rb
189
203
  - lib/dominate/instance.rb
204
+ - lib/dominate/mab.rb
190
205
  - lib/dominate/scope.rb
191
206
  - lib/dominate/version.rb
192
207
  - lib/dominate/widget.rb