gakubuchi 1.3.0 → 1.4.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/README.md +9 -9
- data/lib/gakubuchi.rb +2 -32
- data/lib/gakubuchi/configuration.rb +20 -0
- data/lib/gakubuchi/engine_registrar.rb +36 -12
- data/lib/gakubuchi/error.rb +4 -2
- data/lib/gakubuchi/fileutils.rb +4 -0
- data/lib/gakubuchi/mime_type.rb +21 -0
- data/lib/gakubuchi/railtie.rb +19 -3
- data/lib/gakubuchi/rake_task.rb +36 -0
- data/lib/gakubuchi/task.rb +8 -2
- data/lib/gakubuchi/template.rb +12 -3
- data/lib/gakubuchi/version.rb +2 -1
- data/lib/generators/gakubuchi/install/install_generator.rb +5 -0
- data/lib/tasks/after_precompile.rake +4 -0
- metadata +26 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e79a372af60dae91f7a2800bf92105775443301
|
4
|
+
data.tar.gz: f5f85209a9cbb2d8d051f184e56daa6509ceb1a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5ad244af5a0a6d1294b953e9869252329c5b12a80c605956330dd91c273dbda10acf15531808d37380eb31f363a0f642b5442e2adf56a6a81850cdc40b9e1bc
|
7
|
+
data.tar.gz: a63cba1baa07b640d5ce4d2645cc5646133a30a9b7c5a1d418dac7b73d5424e63804df31a4ffa55b561010f06942194ca9085dea948f2cd67ba2e5bdb8579946
|
data/README.md
CHANGED
@@ -17,13 +17,13 @@ gem 'gakubuchi'
|
|
17
17
|
Run the installation generator with:
|
18
18
|
|
19
19
|
```shell
|
20
|
-
rails
|
20
|
+
rails g gakubuchi:install
|
21
21
|
```
|
22
22
|
|
23
23
|
Or specify the name of directory for static pages:
|
24
24
|
|
25
25
|
```shell
|
26
|
-
rails
|
26
|
+
rails g gakubuchi:install -d html
|
27
27
|
```
|
28
28
|
|
29
29
|
They will install the initializer into `config/initializers/gakubuchi.rb` and create the directory in `app/assets`.
|
@@ -57,21 +57,21 @@ http://localhost:3000/assets/404.html
|
|
57
57
|
Compile the templeate with:
|
58
58
|
|
59
59
|
```shell
|
60
|
-
|
60
|
+
rails assets:precompile
|
61
61
|
```
|
62
62
|
|
63
63
|
This will generate `public/404.html`.
|
64
64
|
|
65
65
|
## Template engines
|
66
66
|
Gakubuchi supports some template engines: `ERB`, `Haml` and `Slim`.
|
67
|
-
|
67
|
+
When you want to use `Haml` or `Slim`, you need to put them in your Gemfile:
|
68
68
|
|
69
69
|
```ruby
|
70
70
|
# Use Haml
|
71
|
-
gem 'haml
|
71
|
+
gem 'haml'
|
72
72
|
|
73
73
|
# Use Slim
|
74
|
-
gem 'slim
|
74
|
+
gem 'slim'
|
75
75
|
```
|
76
76
|
|
77
77
|
## Using assets
|
@@ -111,9 +111,9 @@ You should follow the steps below.
|
|
111
111
|
|
112
112
|
1. [Fork the repository](https://help.github.com/articles/fork-a-repo/)
|
113
113
|
2. Create a feature branch: `git checkout -b add-new-feature`
|
114
|
-
3. Commit your changes: `git commit -am '
|
114
|
+
3. Commit your changes: `git commit -am 'Add new feature'`
|
115
115
|
4. Push the branch: `git push origin add-new-feature`
|
116
|
-
4. [Send us a pull request](https://help.github.com/articles/
|
116
|
+
4. [Send us a pull request](https://help.github.com/articles/about-pull-requests/)
|
117
117
|
|
118
118
|
We use [Appraisal](https://github.com/thoughtbot/appraisal) to test with different combinations of
|
119
119
|
[sprockets](https://github.com/rails/sprockets) and [sprockets-rails](https://github.com/rails/sprockets-rails).
|
@@ -123,7 +123,7 @@ bundle install
|
|
123
123
|
appraisal install
|
124
124
|
|
125
125
|
# Run RSpec with a specific combination
|
126
|
-
appraisal 'sprockets-rails 3 with sprockets
|
126
|
+
appraisal 'sprockets-rails 3 with sprockets 4' rspec
|
127
127
|
|
128
128
|
# Run RSpec with all combinations
|
129
129
|
appraisal rspec
|
data/lib/gakubuchi.rb
CHANGED
@@ -1,35 +1,5 @@
|
|
1
|
-
|
2
|
-
require "forwardable"
|
3
|
-
require "logger"
|
4
|
-
require "active_support/configurable"
|
5
|
-
|
1
|
+
# frozen_string_literal: true
|
6
2
|
require "gakubuchi/configuration"
|
7
|
-
require "gakubuchi/
|
8
|
-
require "gakubuchi/fileutils"
|
3
|
+
require "gakubuchi/railtie"
|
9
4
|
require "gakubuchi/task"
|
10
5
|
require "gakubuchi/version"
|
11
|
-
|
12
|
-
if defined?(::Rails::Railtie) && defined?(::Sprockets::Railtie)
|
13
|
-
require "pathname"
|
14
|
-
require "gakubuchi/engine_registrar"
|
15
|
-
require "gakubuchi/template"
|
16
|
-
require "gakubuchi/railtie"
|
17
|
-
end
|
18
|
-
|
19
|
-
module Gakubuchi
|
20
|
-
class << self
|
21
|
-
attr_writer :configuration
|
22
|
-
|
23
|
-
def configuration
|
24
|
-
@configuration ||= Configuration.new
|
25
|
-
end
|
26
|
-
|
27
|
-
def configure
|
28
|
-
yield(configuration) if block_given?
|
29
|
-
end
|
30
|
-
|
31
|
-
def reset
|
32
|
-
@configuration = nil
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1,4 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "active_support/configurable"
|
3
|
+
require "forwardable"
|
4
|
+
|
1
5
|
module Gakubuchi
|
6
|
+
class << self
|
7
|
+
attr_writer :configuration
|
8
|
+
|
9
|
+
def configuration
|
10
|
+
@configuration ||= ::Gakubuchi::Configuration.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def configure
|
14
|
+
yield(configuration) if block_given?
|
15
|
+
end
|
16
|
+
|
17
|
+
def reset
|
18
|
+
@configuration = nil
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
2
22
|
class Configuration
|
3
23
|
extend ::Forwardable
|
4
24
|
include ::ActiveSupport::Configurable
|
@@ -1,30 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "active_support/inflector"
|
3
|
+
require "grease"
|
4
|
+
require "sprockets"
|
5
|
+
|
1
6
|
module Gakubuchi
|
2
7
|
class EngineRegistrar
|
8
|
+
EXTENSION_WITH_SIGLE_DOT = /\A\.[^\.]+\z/
|
9
|
+
|
3
10
|
def initialize(env)
|
4
11
|
@env = env
|
5
12
|
end
|
6
13
|
|
7
|
-
def register(
|
8
|
-
|
9
|
-
return false if !
|
14
|
+
def register(mime_type, engine_name_or_class)
|
15
|
+
engine = constantize(engine_name_or_class)
|
16
|
+
return false if !engine.instance_of?(::Class) || mime_type.extensions.empty?
|
10
17
|
|
11
|
-
|
12
|
-
|
18
|
+
if sprockets_major_version >= 4
|
19
|
+
register_as_transformer(mime_type, engine)
|
20
|
+
else
|
21
|
+
register_as_engine(mime_type, engine)
|
22
|
+
end
|
13
23
|
|
14
|
-
@env.register_engine(*args)
|
15
24
|
true
|
16
25
|
end
|
17
26
|
|
18
|
-
def registered?(target)
|
19
|
-
@env.engines.key?(::Sprockets::Utils.normalize_extension(target))
|
20
|
-
end
|
21
|
-
|
22
27
|
private
|
23
28
|
|
24
|
-
def constantize(
|
25
|
-
|
29
|
+
def constantize(constant_name)
|
30
|
+
constant_name.to_s.constantize
|
26
31
|
rescue ::LoadError, ::NameError
|
27
32
|
nil
|
28
33
|
end
|
34
|
+
|
35
|
+
def sprockets_major_version
|
36
|
+
@sprockets_major_version ||= ::Gem::Version.new(::Sprockets::VERSION).segments.first
|
37
|
+
end
|
38
|
+
|
39
|
+
def register_as_engine(mime_type, engine)
|
40
|
+
mime_type.extensions.select { |ext| ext =~ EXTENSION_WITH_SIGLE_DOT }.each do |ext|
|
41
|
+
args = [ext, engine]
|
42
|
+
args << { silence_deprecation: true } if sprockets_major_version == 3
|
43
|
+
@env.register_engine(*args)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def register_as_transformer(mime_type, engine)
|
48
|
+
content_type = mime_type.content_type
|
49
|
+
|
50
|
+
@env.register_mime_type(content_type, extensions: mime_type.extensions)
|
51
|
+
@env.register_transformer(content_type, engine.default_mime_type, ::Grease.apply(engine))
|
52
|
+
end
|
29
53
|
end
|
30
54
|
end
|
data/lib/gakubuchi/error.rb
CHANGED
data/lib/gakubuchi/fileutils.rb
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "gakubuchi/error"
|
3
|
+
require "set"
|
4
|
+
|
5
|
+
module Gakubuchi
|
6
|
+
class MimeType
|
7
|
+
CONTENT_TYPE_FORMAT = %r(\A[^/]+/[^/]+\z)
|
8
|
+
|
9
|
+
attr_reader :content_type, :extensions
|
10
|
+
|
11
|
+
def initialize(content_type, extensions: [])
|
12
|
+
unless content_type =~ CONTENT_TYPE_FORMAT
|
13
|
+
message = %(`#{content_type}' is invalid as Content-Type)
|
14
|
+
raise ::Gakubuchi::Error::InvalidMimeType, message
|
15
|
+
end
|
16
|
+
|
17
|
+
@content_type = content_type
|
18
|
+
@extensions = ::Set.new(extensions).map(&:to_s)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/gakubuchi/railtie.rb
CHANGED
@@ -1,10 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "gakubuchi/engine_registrar"
|
3
|
+
require "gakubuchi/mime_type"
|
4
|
+
require "gakubuchi/template"
|
5
|
+
require "rails/railtie"
|
6
|
+
require "sprockets/railtie"
|
7
|
+
|
1
8
|
module Gakubuchi
|
2
9
|
class Railtie < ::Rails::Railtie
|
3
10
|
config.assets.configure do |env|
|
4
|
-
engine_registrar = EngineRegistrar.new(env)
|
11
|
+
engine_registrar = ::Gakubuchi::EngineRegistrar.new(env)
|
12
|
+
|
13
|
+
haml = ::Gakubuchi::MimeType.new("text/haml", extensions: %w(.haml .html.haml))
|
14
|
+
engine_registrar.register(haml, "Tilt::HamlTemplate")
|
15
|
+
|
16
|
+
slim = ::Gakubuchi::MimeType.new("text/slim", extensions: %w(.slim .html.slim))
|
17
|
+
engine_registrar.register(slim, "Slim::Template")
|
18
|
+
end
|
5
19
|
|
6
|
-
|
7
|
-
|
20
|
+
config.after_initialize do
|
21
|
+
# NOTE: Call #to_s for Sprockets 4 or later
|
22
|
+
templates = ::Gakubuchi::Template.all.map { |template| template.logical_path.to_s }
|
23
|
+
config.assets.precompile += templates
|
8
24
|
end
|
9
25
|
|
10
26
|
rake_tasks do
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "gakubuchi/task"
|
3
|
+
require "rake"
|
4
|
+
require "rake/tasklib"
|
5
|
+
require "sprockets/railtie"
|
6
|
+
|
7
|
+
rake_tasks do
|
8
|
+
::Gakubuchi::RakeTask.new do |task|
|
9
|
+
task.templates = %w(foo.slim bar.slim)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
module Gakubuchi
|
14
|
+
class RakeTask < ::Rake::TaskLib
|
15
|
+
attr_accessor :templates
|
16
|
+
|
17
|
+
def initialize(target_task = "assets:precompile")
|
18
|
+
self.target_task = target_task
|
19
|
+
self.templates = []
|
20
|
+
self.verbose = true
|
21
|
+
|
22
|
+
yield self if block_given?
|
23
|
+
enhance_target_task
|
24
|
+
end
|
25
|
+
|
26
|
+
def task
|
27
|
+
@task ||= ::Gakubuchi::Task.new(templates, verbose: verbose)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def enhance_target_task
|
33
|
+
::Rake::Task[target_task].enhance { task.execute! }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/gakubuchi/task.rb
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "gakubuchi/configuration"
|
3
|
+
require "gakubuchi/fileutils"
|
4
|
+
|
1
5
|
module Gakubuchi
|
2
6
|
class Task
|
3
7
|
attr_reader :templates
|
@@ -12,9 +16,11 @@ module Gakubuchi
|
|
12
16
|
next if src.nil?
|
13
17
|
|
14
18
|
dest = template.destination_path
|
15
|
-
FileUtils.copy_p(src, dest)
|
19
|
+
::Gakubuchi::FileUtils.copy_p(src, dest)
|
16
20
|
|
17
|
-
|
21
|
+
unless leave_digest_named_templates?
|
22
|
+
::Gakubuchi::FileUtils.remove([src, *::Dir.glob("#{src}.gz")])
|
23
|
+
end
|
18
24
|
end
|
19
25
|
end
|
20
26
|
|
data/lib/gakubuchi/template.rb
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "forwardable"
|
3
|
+
require "gakubuchi/configuration"
|
4
|
+
require "gakubuchi/error"
|
5
|
+
require "pathname"
|
6
|
+
require "rails"
|
7
|
+
require "sprockets/railtie"
|
8
|
+
|
1
9
|
module Gakubuchi
|
2
10
|
class Template
|
3
11
|
extend ::Forwardable
|
@@ -28,9 +36,9 @@ module Gakubuchi
|
|
28
36
|
|
29
37
|
case
|
30
38
|
when !@extname.include?("html")
|
31
|
-
|
39
|
+
raise ::Gakubuchi::Error::InvalidTemplate, "source path must refer to a template file"
|
32
40
|
when !@source_path.fnmatch?(root.join("*").to_s)
|
33
|
-
|
41
|
+
raise ::Gakubuchi::Error::InvalidTemplate, "template must exist in #{root}"
|
34
42
|
end
|
35
43
|
end
|
36
44
|
|
@@ -39,7 +47,8 @@ module Gakubuchi
|
|
39
47
|
end
|
40
48
|
|
41
49
|
def digest_path
|
42
|
-
|
50
|
+
# NOTE: Call #to_s for Sprockets 4 or later
|
51
|
+
asset = assets.find_asset(logical_path.to_s)
|
43
52
|
return if asset.nil?
|
44
53
|
|
45
54
|
::Pathname.new(::File.join(::Rails.public_path, app.config.assets.prefix, asset.digest_path))
|
data/lib/gakubuchi/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gakubuchi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yasaichi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-04-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: grease
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.3.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.3.0
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: railties
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -98,16 +112,16 @@ dependencies:
|
|
98
112
|
name: reek
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
100
114
|
requirements:
|
101
|
-
- - "
|
115
|
+
- - ">="
|
102
116
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
117
|
+
version: '0'
|
104
118
|
type: :development
|
105
119
|
prerelease: false
|
106
120
|
version_requirements: !ruby/object:Gem::Requirement
|
107
121
|
requirements:
|
108
|
-
- - "
|
122
|
+
- - ">="
|
109
123
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
124
|
+
version: '0'
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
126
|
name: rspec-rails
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -154,16 +168,16 @@ dependencies:
|
|
154
168
|
name: slim-rails
|
155
169
|
requirement: !ruby/object:Gem::Requirement
|
156
170
|
requirements:
|
157
|
-
- - "
|
171
|
+
- - "<"
|
158
172
|
- !ruby/object:Gem::Version
|
159
|
-
version:
|
173
|
+
version: 3.1.1
|
160
174
|
type: :development
|
161
175
|
prerelease: false
|
162
176
|
version_requirements: !ruby/object:Gem::Requirement
|
163
177
|
requirements:
|
164
|
-
- - "
|
178
|
+
- - "<"
|
165
179
|
- !ruby/object:Gem::Version
|
166
|
-
version:
|
180
|
+
version: 3.1.1
|
167
181
|
- !ruby/object:Gem::Dependency
|
168
182
|
name: sqlite3
|
169
183
|
requirement: !ruby/object:Gem::Requirement
|
@@ -193,7 +207,9 @@ files:
|
|
193
207
|
- lib/gakubuchi/engine_registrar.rb
|
194
208
|
- lib/gakubuchi/error.rb
|
195
209
|
- lib/gakubuchi/fileutils.rb
|
210
|
+
- lib/gakubuchi/mime_type.rb
|
196
211
|
- lib/gakubuchi/railtie.rb
|
212
|
+
- lib/gakubuchi/rake_task.rb
|
197
213
|
- lib/gakubuchi/task.rb
|
198
214
|
- lib/gakubuchi/template.rb
|
199
215
|
- lib/gakubuchi/version.rb
|