gakubuchi 1.1.0 → 1.2.0
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.
- checksums.yaml +4 -4
- data/MIT-LICENSE +1 -1
- data/lib/gakubuchi/engine_registrar.rb +27 -0
- data/lib/gakubuchi/error.rb +5 -0
- data/lib/gakubuchi/railtie.rb +5 -3
- data/lib/gakubuchi/task.rb +2 -2
- data/lib/gakubuchi/template.rb +34 -25
- data/lib/gakubuchi/version.rb +1 -1
- data/lib/gakubuchi.rb +2 -1
- metadata +8 -7
- data/lib/gakubuchi/template_engine.rb +0 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c899d677ecc5feddbca366ee1b59e5ecc22e307
|
4
|
+
data.tar.gz: 2db0642f6fc120915d464ff07f01392d81d2aa12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc51f9de01fa55a1c0db624963e46271f8787de54cf23e9bb03d0a7a286c44fef7fce0461584325ed749ec75b35b1d04fb5465966d332f8a584b456cf8433a6a
|
7
|
+
data.tar.gz: 90c16f8304742a31e13a9291261bf9f6fe313aafdc6ae46fc85559b459261fb4327ab9dab3d0c31942e9a16a148b06cef7669f78561a46f0a7d03856c92c12cb
|
data/MIT-LICENSE
CHANGED
@@ -0,0 +1,27 @@
|
|
1
|
+
module Gakubuchi
|
2
|
+
class EngineRegistrar
|
3
|
+
def initialize(env)
|
4
|
+
@env = env
|
5
|
+
end
|
6
|
+
|
7
|
+
def register(target, engine)
|
8
|
+
klass = constantize(engine)
|
9
|
+
return false if !klass.instance_of?(::Class) || registered?(target)
|
10
|
+
|
11
|
+
@env.register_engine(target, klass)
|
12
|
+
true
|
13
|
+
end
|
14
|
+
|
15
|
+
def registered?(target)
|
16
|
+
@env.engines.key?(::Sprockets::Utils.normalize_extension(target))
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def constantize(klass)
|
22
|
+
klass.to_s.constantize
|
23
|
+
rescue ::NameError
|
24
|
+
nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/gakubuchi/railtie.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
module Gakubuchi
|
2
2
|
class Railtie < ::Rails::Railtie
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
config.assets.configure do |env|
|
4
|
+
engine_registrar = EngineRegistrar.new(env)
|
5
|
+
|
6
|
+
engine_registrar.register(:haml, '::Tilt::HamlTemplate')
|
7
|
+
engine_registrar.register(:slim, '::Slim::Template')
|
6
8
|
end
|
7
9
|
|
8
10
|
rake_tasks do
|
data/lib/gakubuchi/task.rb
CHANGED
@@ -8,10 +8,10 @@ module Gakubuchi
|
|
8
8
|
|
9
9
|
def execute!
|
10
10
|
templates.each do |template|
|
11
|
-
src = template.
|
11
|
+
src = template.digest_path
|
12
12
|
next if src.nil?
|
13
13
|
|
14
|
-
dest = template.
|
14
|
+
dest = template.destination_path
|
15
15
|
FileUtils.copy_p(src, dest)
|
16
16
|
|
17
17
|
FileUtils.remove(src) unless leave_digest_named_templates?
|
data/lib/gakubuchi/template.rb
CHANGED
@@ -2,54 +2,63 @@ module Gakubuchi
|
|
2
2
|
class Template
|
3
3
|
extend ::Forwardable
|
4
4
|
|
5
|
-
attr_reader :
|
6
|
-
|
5
|
+
attr_reader :source_path, :extname
|
6
|
+
def_delegators :source_path, :basename, :hash
|
7
7
|
|
8
8
|
%w(== === eql?).each do |method_name|
|
9
9
|
define_method(method_name) do |other|
|
10
|
-
self.class == other.class &&
|
10
|
+
self.class == other.class && source_path.public_send(method_name, other.source_path)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
14
|
def self.all
|
15
|
-
::Dir.glob(root.join('**/*.html*')).map { |
|
15
|
+
::Dir.glob(root.join('**/*.html*')).map { |source_path| new(source_path) }
|
16
16
|
end
|
17
17
|
|
18
18
|
def self.root
|
19
19
|
::Rails.root.join('app/assets', ::Gakubuchi.configuration.template_directory)
|
20
20
|
end
|
21
21
|
|
22
|
-
def initialize(
|
23
|
-
|
24
|
-
|
22
|
+
def initialize(source_path)
|
23
|
+
path = ::Pathname.new(source_path)
|
24
|
+
root = self.class.root
|
25
|
+
|
26
|
+
@extname = extract_extname(path)
|
27
|
+
@source_path = path.absolute? ? path : root.join(path)
|
25
28
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
+
case
|
30
|
+
when !@extname.include?('html')
|
31
|
+
fail Error::InvalidTemplate, 'source path must refer to a template file'
|
32
|
+
when !@source_path.fnmatch?(root.join('*').to_s)
|
33
|
+
fail Error::InvalidTemplate, "template must exist in #{root}"
|
34
|
+
end
|
29
35
|
end
|
30
36
|
|
31
|
-
def
|
32
|
-
|
33
|
-
|
37
|
+
def destination_path
|
38
|
+
::Rails.public_path.join(logical_path)
|
39
|
+
end
|
34
40
|
|
35
|
-
|
36
|
-
|
37
|
-
|
41
|
+
def digest_path
|
42
|
+
resolved_path = view_context.asset_digest_path(logical_path.to_s)
|
43
|
+
return if resolved_path.nil?
|
38
44
|
|
39
|
-
|
40
|
-
|
41
|
-
end
|
45
|
+
::Pathname.new(::File.join(::Rails.public_path, view_context.assets_prefix, resolved_path))
|
46
|
+
end
|
42
47
|
|
43
|
-
|
48
|
+
def logical_path
|
49
|
+
dirname = source_path.relative_path_from(self.class.root).dirname
|
50
|
+
::Pathname.new(dirname).join("#{basename(extname)}.html")
|
44
51
|
end
|
45
52
|
|
46
|
-
|
47
|
-
|
48
|
-
|
53
|
+
private
|
54
|
+
|
55
|
+
def extract_extname(path)
|
56
|
+
extname = path.extname
|
57
|
+
extname.empty? ? extname : "#{extract_extname(path.basename(extname))}#{extname}"
|
49
58
|
end
|
50
59
|
|
51
|
-
def
|
52
|
-
|
60
|
+
def view_context
|
61
|
+
@view_context ||= ::ActionView::Base.new
|
53
62
|
end
|
54
63
|
end
|
55
64
|
end
|
data/lib/gakubuchi/version.rb
CHANGED
data/lib/gakubuchi.rb
CHANGED
@@ -4,14 +4,15 @@ require 'logger'
|
|
4
4
|
require 'active_support/configurable'
|
5
5
|
|
6
6
|
require 'gakubuchi/configuration'
|
7
|
+
require 'gakubuchi/error'
|
7
8
|
require 'gakubuchi/fileutils'
|
8
9
|
require 'gakubuchi/task'
|
9
10
|
require 'gakubuchi/version'
|
10
11
|
|
11
12
|
if defined?(::Rails::Railtie) && defined?(::Sprockets::Railtie)
|
12
13
|
require 'pathname'
|
14
|
+
require 'gakubuchi/engine_registrar'
|
13
15
|
require 'gakubuchi/template'
|
14
|
-
require 'gakubuchi/template_engine'
|
15
16
|
require 'gakubuchi/railtie'
|
16
17
|
end
|
17
18
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gakubuchi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yasaichi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: sprockets-rails
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 2.0.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 2.0.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: ammeter
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -190,11 +190,12 @@ files:
|
|
190
190
|
- Rakefile
|
191
191
|
- lib/gakubuchi.rb
|
192
192
|
- lib/gakubuchi/configuration.rb
|
193
|
+
- lib/gakubuchi/engine_registrar.rb
|
194
|
+
- lib/gakubuchi/error.rb
|
193
195
|
- lib/gakubuchi/fileutils.rb
|
194
196
|
- lib/gakubuchi/railtie.rb
|
195
197
|
- lib/gakubuchi/task.rb
|
196
198
|
- lib/gakubuchi/template.rb
|
197
|
-
- lib/gakubuchi/template_engine.rb
|
198
199
|
- lib/gakubuchi/version.rb
|
199
200
|
- lib/generators/gakubuchi/install/install_generator.rb
|
200
201
|
- lib/generators/gakubuchi/install/templates/gakubuchi.rb.erb
|
@@ -1,29 +0,0 @@
|
|
1
|
-
module Gakubuchi
|
2
|
-
class TemplateEngine
|
3
|
-
extend ::Forwardable
|
4
|
-
|
5
|
-
attr_reader :klass
|
6
|
-
alias_method :engine, :klass
|
7
|
-
|
8
|
-
def_delegator '::Rails.application', :assets
|
9
|
-
def_delegator '::Sprockets::Utils', :normalize_extension
|
10
|
-
private :assets, :normalize_extension
|
11
|
-
|
12
|
-
def initialize(engine)
|
13
|
-
@klass = engine.to_s.constantize rescue nil
|
14
|
-
end
|
15
|
-
|
16
|
-
def register!(extname)
|
17
|
-
if engine.instance_of?(::Class) && !registered?(extname)
|
18
|
-
!!assets.register_engine(extname, engine)
|
19
|
-
else
|
20
|
-
false
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def registered?(extname)
|
25
|
-
ext = normalize_extension(extname)
|
26
|
-
assets.engines.key?(ext) && assets.engines[ext] == engine
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|