gakubuchi 0.2.2 → 1.0.0.rc2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1edba3f60856d88e7f5529bdbce93eecc0a35313
4
- data.tar.gz: 32a2cf35012a653ca428642c13b1a0bc3583a7a9
3
+ metadata.gz: 24f1923fe8e330d09cd3297d4eab8eb3707417c8
4
+ data.tar.gz: 6b6960e650da43d042f666c8dcee139ec5e50664
5
5
  SHA512:
6
- metadata.gz: b813c7f0e3745f402df939554df6bdd047ded8387ea81fc74dae8d12042f468dd5f1e94dae5519aa894adce4695c5488106bbb71ae8b33f1627f75c227262c8b
7
- data.tar.gz: 933d064cf2693a53698e4809cc1824e5de2976d05ade332fa31ddc99efb67ebe395b58911034d3535bdcf767b3fcb7480472902362dc084e4543739fee9ed016
6
+ metadata.gz: 76a1cafe291e2264a0832315fbc501bb9afc590187f6546bc59510b8b7e8c7509e0647b37f05881bd8a9a89d5c94cf9b30df45e63206d6f21b9d298b2a214244
7
+ data.tar.gz: e2e8e17b243aae14a0ec7ed71ddb02278bab8eb5dc93f666ad29de35f175aec2fca5ec0f6e8a347fa95f9fe5f87b87e691300178a7f020a1e49b4858d9e806cc
data/README.md CHANGED
@@ -7,13 +7,30 @@
7
7
 
8
8
  Gakubuchi provides a simple way to manage static pages (e.g. error pages) with Asset Pipeline.
9
9
 
10
- ## Quickstart
10
+ ## Installation
11
11
  Put this in your Gemfile:
12
12
 
13
13
  ```ruby
14
14
  gem 'gakubuchi'
15
15
  ```
16
16
 
17
+ Run the installation generator with:
18
+
19
+ ```shell
20
+ rails generate gakubuchi:install
21
+ ```
22
+
23
+ Or specify the name of directory for static pages:
24
+
25
+ ```shell
26
+ rails generate gakubuchi:install -d html
27
+ ```
28
+
29
+ They will install the initializer into `config/initializers/gakubuchi.rb` and create the directory in `app/assets`.
30
+ If you don't specify the `-d` option, `templates` will be used as default.
31
+
32
+ ## Usage
33
+
17
34
  In `app/assets/templates/404.html.slim`:
18
35
 
19
36
  ```slim
@@ -43,7 +60,7 @@ Compile the templeate with:
43
60
  rake assets:precompile
44
61
  ```
45
62
 
46
- Then, you can get `public/404.html`.
63
+ This will generate `public/404.html`.
47
64
 
48
65
  ## Template engines
49
66
  Gakubuchi supports some template engines: `ERB`, `Haml` and `Slim`.
@@ -57,20 +74,20 @@ gem 'haml-rails'
57
74
  gem 'slim-rails'
58
75
  ```
59
76
 
60
- ## Configuration
61
- First, run the installation generator with:
77
+ ## Using assets
78
+ Gakubuchi enables you to use assets (e.g. `CSS` or `JavaScript` files) in static pages.
79
+ Note that you may need to add them to the precompile array in `config/initializers/assets.rb`:
62
80
 
63
- ```shell
64
- rails generate gakubuchi:install
81
+ ```ruby
82
+ Rails.application.config.assets.precompile += %w(error.css error.js)
65
83
  ```
66
84
 
67
- This will install the initializer into `config/initializers/gakubuchi.rb`.
68
-
69
- In the file, you can configure the following values.
85
+ ## Configuration
86
+ In `config/initializers/gakubuchi.rb`, you can configure the following values.
70
87
 
71
88
  ```
72
89
  remove_precompiled_templates # true by default
73
- template_root # 'app/assets/templates' by default
90
+ template_directory # 'templates' by default
74
91
  ```
75
92
 
76
93
  ## Supported versions
@@ -1,11 +1,19 @@
1
- require 'rails'
1
+ require 'fileutils'
2
+ require 'forwardable'
3
+ require 'logger'
4
+ require 'active_support/configurable'
2
5
 
3
6
  require 'gakubuchi/configuration'
7
+ require 'gakubuchi/fileutils'
4
8
  require 'gakubuchi/task'
5
- require 'gakubuchi/template'
6
- require 'gakubuchi/template_engine'
7
9
  require 'gakubuchi/version'
8
- require 'gakubuchi/engine'
10
+
11
+ if defined?(::Rails::Railtie) && defined?(::Sprockets::Railtie)
12
+ require 'pathname'
13
+ require 'gakubuchi/template'
14
+ require 'gakubuchi/template_engine'
15
+ require 'gakubuchi/railtie'
16
+ end
9
17
 
10
18
  module Gakubuchi
11
19
  class << self
@@ -1,14 +1,17 @@
1
1
  module Gakubuchi
2
2
  class Configuration
3
- include ActiveSupport::Configurable
4
- alias_method :to_h, :config
3
+ extend ::Forwardable
4
+ include ::ActiveSupport::Configurable
5
+
6
+ private :config
7
+ def_delegators :config, :to_h
5
8
 
6
9
  config_accessor :remove_precompiled_templates do
7
10
  true
8
11
  end
9
12
 
10
- config_accessor :template_root do
11
- 'app/assets/templates'
13
+ config_accessor :template_directory do
14
+ 'templates'
12
15
  end
13
16
  end
14
17
  end
@@ -1,12 +1,10 @@
1
- require 'fileutils'
2
-
3
1
  module Gakubuchi
4
2
  module FileUtils
5
3
  extend ::FileUtils
6
4
 
7
5
  class << self
8
6
  def copy_p(src, dest)
9
- mkdir_p(File.dirname(dest))
7
+ mkdir_p(::File.dirname(dest))
10
8
  copy(src, dest)
11
9
  logging("Copied #{src} to #{dest}")
12
10
  end
@@ -19,7 +17,7 @@ module Gakubuchi
19
17
  private
20
18
 
21
19
  def logging(message)
22
- Logger.new(STDOUT).info(message)
20
+ ::Logger.new(STDOUT).info(message)
23
21
  end
24
22
  end
25
23
  end
@@ -1,14 +1,12 @@
1
1
  module Gakubuchi
2
- class Engine < ::Rails::Engine
3
- isolate_namespace Gakubuchi
4
-
5
- config.generators do |g|
6
- g.test_framework :rspec
7
- end
8
-
2
+ class Railtie < ::Rails::Railtie
9
3
  initializer 'gakubuchi.assets.precompile' do |app|
10
4
  TemplateEngine.new('Slim::Template').register!('.slim')
11
5
  TemplateEngine.new('Tilt::HamlTemplate').register!('.haml')
12
6
  end
7
+
8
+ rake_tasks do
9
+ ::Dir.glob(::File.expand_path('../../tasks/*.rake', __FILE__)).each { |path| load path }
10
+ end
13
11
  end
14
12
  end
@@ -1,5 +1,3 @@
1
- require 'gakubuchi/fileutils'
2
-
3
1
  module Gakubuchi
4
2
  class Task
5
3
  attr_reader :templates
@@ -10,18 +8,13 @@ module Gakubuchi
10
8
 
11
9
  def execute!
12
10
  templates.each do |template|
13
- precompiled_pathnames = template.precompiled_pathnames
14
-
15
- src = precompiled_pathnames
16
- .select { |pathname| pathname.extname == '.html' }
17
- .sort_by { |pathname| pathname.mtime }
18
- .last
19
-
11
+ src = template.precompiled_pathname
20
12
  next if src.nil?
21
- dest = template.destination_pathname
22
13
 
14
+ dest = template.destination_pathname
23
15
  FileUtils.copy_p(src, dest)
24
- FileUtils.remove(precompiled_pathnames) if remove_precompiled_templates?
16
+
17
+ FileUtils.remove(src) if remove_precompiled_templates?
25
18
  end
26
19
  end
27
20
 
@@ -13,24 +13,20 @@ module Gakubuchi
13
13
  end
14
14
 
15
15
  def self.all
16
- Dir.glob(root.join('**/*.html*')).map { |path| new(path) }
16
+ ::Dir.glob(root.join('**/*.html*')).map { |path| new(path) }
17
17
  end
18
18
 
19
19
  def self.root
20
- Rails.root.join(Gakubuchi.configuration.template_root)
20
+ ::Rails.root.join('app/assets', Gakubuchi.configuration.template_directory)
21
21
  end
22
22
 
23
23
  def initialize(path)
24
- @pathname = Pathname.new(path)
25
- end
26
-
27
- def basename
28
- pathname.basename.to_s
24
+ @pathname = ::Pathname.new(path)
29
25
  end
30
26
 
31
27
  def destination_pathname
32
28
  dirname = relative_pathname.dirname
33
- Rails.public_path.join(dirname, "#{relative_pathname.basename(extname)}.html")
29
+ ::Rails.public_path.join(dirname, "#{relative_pathname.basename(extname)}.html")
34
30
  end
35
31
 
36
32
  def extname
@@ -48,11 +44,9 @@ module Gakubuchi
48
44
  extnames.join
49
45
  end
50
46
 
51
- def precompiled_pathnames
52
- dirname = relative_pathname.dirname
53
- pattern = "#{relative_pathname.basename(extname)}-*.{html,html.gz}"
54
-
55
- Pathname.glob(Rails.public_path.join('assets', dirname, pattern))
47
+ def precompiled_pathname
48
+ asset = ::Rails.application.assets.find_asset(relative_pathname)
49
+ ::Rails.public_path.join('assets', asset.digest_path) if asset
56
50
  end
57
51
 
58
52
  def relative_pathname
@@ -5,8 +5,8 @@ module Gakubuchi
5
5
  attr_reader :klass
6
6
  alias_method :engine, :klass
7
7
 
8
- def_delegators 'Rails.application', :assets
9
- def_delegators 'Sprockets::Utils', :normalize_extension
8
+ def_delegators '::Rails.application', :assets
9
+ def_delegators '::Sprockets::Utils', :normalize_extension
10
10
  private :assets, :normalize_extension
11
11
 
12
12
  def initialize(engine)
@@ -1,3 +1,3 @@
1
1
  module Gakubuchi
2
- VERSION = '0.2.2'
2
+ VERSION = '1.0.0.rc2'
3
3
  end
@@ -1,10 +1,23 @@
1
1
  module Gakubuchi
2
2
  module Generators
3
- class InstallGenerator < Rails::Generators::Base
4
- source_root File.expand_path('../templates', __FILE__)
3
+ class InstallGenerator < ::Rails::Generators::Base
4
+ DEFAULT_DIRECTORY = Gakubuchi::Configuration.new.template_directory.freeze
5
+
6
+ desc 'Create a Gakubuchi initializer.'
7
+ source_root ::File.expand_path('../templates', __FILE__)
8
+
9
+ class_option :directory,
10
+ type: :string,
11
+ aliases: '-d',
12
+ default: DEFAULT_DIRECTORY,
13
+ desc: 'Name of directory for templates'
5
14
 
6
15
  def copy_initializer_file
7
- copy_file 'gakubuchi.rb', 'config/initializers/gakubuchi.rb'
16
+ template 'gakubuchi.rb', 'config/initializers/gakubuchi.rb'
17
+ end
18
+
19
+ def create_template_directory
20
+ empty_directory Pathname.new('app/assets').join(options.directory)
8
21
  end
9
22
  end
10
23
  end
@@ -3,7 +3,12 @@ Gakubuchi.configure do |config|
3
3
  # in public/assets. By default, Gakubuchi removes them after the precompile.
4
4
  # config.remove_precompiled_templates = true
5
5
 
6
- # The directory for static pages you want to manage with Asset Pipeline.
7
- # 'app/assets/templates' by default.
8
- # config.template_root = 'app/assets/templates'
6
+ # Name of directory for templates ('<%= DEFAULT_DIRECTORY %>' by default).
7
+ # Gakubuchi treats "app/assets/#{config.template_directory}" as root directory
8
+ # for static pages you want to manage with Asset Pipeline.
9
+ <%- if options.directory.blank? || options.directory == DEFAULT_DIRECTORY -%>
10
+ # config.template_directory = '<%= DEFAULT_DIRECTORY %>'
11
+ <%- else -%>
12
+ config.template_directory = '<%= options.directory %>'
13
+ <%- end -%>
9
14
  end
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gakubuchi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 1.0.0.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - yasaichi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-13 00:00:00.000000000 Z
11
+ date: 2015-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rails
14
+ name: railties
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 4.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: sprockets-rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 2.0.0
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: sqlite3
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -132,11 +146,10 @@ files:
132
146
  - MIT-LICENSE
133
147
  - README.md
134
148
  - Rakefile
135
- - config/routes.rb
136
149
  - lib/gakubuchi.rb
137
150
  - lib/gakubuchi/configuration.rb
138
- - lib/gakubuchi/engine.rb
139
151
  - lib/gakubuchi/fileutils.rb
152
+ - lib/gakubuchi/railtie.rb
140
153
  - lib/gakubuchi/task.rb
141
154
  - lib/gakubuchi/template.rb
142
155
  - lib/gakubuchi/template_engine.rb
@@ -156,12 +169,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
156
169
  requirements:
157
170
  - - ">="
158
171
  - !ruby/object:Gem::Version
159
- version: '0'
172
+ version: 2.0.0
160
173
  required_rubygems_version: !ruby/object:Gem::Requirement
161
174
  requirements:
162
- - - ">="
175
+ - - ">"
163
176
  - !ruby/object:Gem::Version
164
- version: '0'
177
+ version: 1.3.1
165
178
  requirements: []
166
179
  rubyforge_project:
167
180
  rubygems_version: 2.4.5
@@ -1,2 +0,0 @@
1
- Rails.application.routes.draw do
2
- end