gakubuchi 0.0.2 → 0.0.3

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: 898ea44bc282dc24bfb9a7c3aaee3788acb1766c
4
- data.tar.gz: 1723a43f1d413a703346063a197b04b9e0eb730a
3
+ metadata.gz: 65b9973f3452444b6bad13a88692fc971ae910d0
4
+ data.tar.gz: e382605a7813b7b301f979828a28096300bf8935
5
5
  SHA512:
6
- metadata.gz: a839d3064b2d6d4d80a7f06b2e32568e7296b2db5d360836e79fb125fb033058213e015e5014ca1dcbf4820a359c4b4a431dd7bb57a8532614fddcc9927a4e9c
7
- data.tar.gz: 2e0d1e29093d1cab7e48d2337af926711cb9e2e00bb5bca04416b9021f57941a47666ca71580113e5abe100dfdde5a9450d5e23fa14d56a487686e4baf56f883
6
+ metadata.gz: 331928a87a5c61e1cf47ed78ebe391d44c1d194973b62cd5f2df0022599cb9d265e106731cdf392192d4975c503a1c6d164c3de7ead456f338d635a83419fbb1
7
+ data.tar.gz: 2ad9268df58198359b39d6f21744cf71c73950fd682f2025992dc4890ab7ad89bf2c37e4c225e51d2041a6355cfc87728a7e30a9dde5f62d9373c7ede677321d
@@ -3,6 +3,10 @@ module Gakubuchi
3
3
  include ActiveSupport::Configurable
4
4
  alias_method :to_h, :config
5
5
 
6
+ config_accessor :remove_precompiled_templates do
7
+ true
8
+ end
9
+
6
10
  config_accessor :template_root do
7
11
  'app/assets/templates'
8
12
  end
@@ -0,0 +1,26 @@
1
+ require 'fileutils'
2
+
3
+ module Gakubuchi
4
+ module FileUtils
5
+ extend ::FileUtils
6
+
7
+ class << self
8
+ def copy_p(src, dest)
9
+ mkdir_p(File.dirname(dest))
10
+ copy(src, dest)
11
+ logging("Copied #{src} to #{dest}")
12
+ end
13
+
14
+ def remove(list)
15
+ super(list)
16
+ logging("Removed #{list.join(' ')}")
17
+ end
18
+
19
+ private
20
+
21
+ def logging(message)
22
+ Logger.new(STDOUT).info(message)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,4 +1,4 @@
1
- require 'fileutils'
1
+ require 'gakubuchi/fileutils'
2
2
 
3
3
  module Gakubuchi
4
4
  class Task
@@ -8,42 +8,25 @@ module Gakubuchi
8
8
  @templates = Array(templates)
9
9
  end
10
10
 
11
- def remove_compiled_files?
12
- !!Gakubuchi.configuration.remove_compiled_files
13
- end
14
-
15
11
  def execute!
16
12
  templates.each do |template|
17
- compiled_paths = Dir.glob(template.compiled_pathname)
18
- src = compiled_paths
19
- .select { |path| File.extname(path) == '.html' }
20
- .sort_by { |path| File.mtime(path) }
13
+ precompiled_pathnames = template.precompiled_pathnames
14
+
15
+ src = precompiled_pathnames
16
+ .select { |pathname| pathname.extname == '.html' }
17
+ .sort_by { |pathname| pathname.mtime }
21
18
  .last
22
19
 
23
20
  next if src.nil?
24
21
  dest = template.destination_pathname
25
22
 
26
- copy(src, dest)
27
- remove(compiled_paths) if remove_compiled_files?
23
+ Gakubuchi::FileUtils.copy_p(src, dest)
24
+ Gakubuchi::FileUtils.remove(precompiled_pathnames) if remove_precompiled_templates?
28
25
  end
29
26
  end
30
27
 
31
- private
32
-
33
- def copy(src, dest)
34
- FileUtils.mkdir_p(File.dirname(dest))
35
- FileUtils.cp(src, dest)
36
- log("Copied #{src} to #{dest}")
37
- end
38
-
39
- def log(message)
40
- @logger ||= Logger.new(STDOUT)
41
- @logger.info(message)
42
- end
43
-
44
- def remove(list)
45
- FileUtils.rm(list)
46
- log("Removed #{list.join(' ')}")
28
+ def remove_precompiled_templates?
29
+ !!Gakubuchi.configuration.remove_precompiled_templates
47
30
  end
48
31
  end
49
32
  end
@@ -1,6 +1,16 @@
1
1
  module Gakubuchi
2
2
  class Template
3
+ extend ::Forwardable
4
+
3
5
  attr_reader :pathname
6
+ def_delegators :@pathname, :hash
7
+
8
+ %w(== === eql?).each do |method_name|
9
+ define_method(method_name) do |other|
10
+ other.respond_to?(:pathname) &&
11
+ @pathname.__send__(method_name, other.pathname)
12
+ end
13
+ end
4
14
 
5
15
  def self.all
6
16
  Dir.glob(root.join('**/*.html*')).map { |path| new(path) }
@@ -18,12 +28,6 @@ module Gakubuchi
18
28
  pathname.basename.to_s
19
29
  end
20
30
 
21
- def compiled_pathname
22
- dirname = relative_pathname.dirname
23
- pattern = "#{relative_pathname.basename(extname)}-*.{html,html.gz}"
24
- Rails.public_path.join('assets', dirname, pattern)
25
- end
26
-
27
31
  def destination_pathname
28
32
  dirname = relative_pathname.dirname
29
33
  Rails.public_path.join(dirname, "#{relative_pathname.basename(extname)}.html")
@@ -44,6 +48,13 @@ module Gakubuchi
44
48
  extnames.join
45
49
  end
46
50
 
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))
56
+ end
57
+
47
58
  def relative_pathname
48
59
  pathname.relative_path_from(self.class.root)
49
60
  end
@@ -1,3 +1,3 @@
1
1
  module Gakubuchi
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
data/lib/gakubuchi.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'rails'
2
2
 
3
3
  require 'gakubuchi/configuration'
4
+ require 'gakubuchi/task'
4
5
  require 'gakubuchi/template'
5
6
  require 'gakubuchi/version'
6
7
  require 'gakubuchi/engine'
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: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - yasaichi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-19 00:00:00.000000000 Z
11
+ date: 2015-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry-byebug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  description: Gakubuchi enables you to manage static pages with Asset Pipeline
84
98
  email:
85
99
  - yasaichi@users.noreply.github.com
@@ -94,6 +108,7 @@ files:
94
108
  - lib/gakubuchi.rb
95
109
  - lib/gakubuchi/configuration.rb
96
110
  - lib/gakubuchi/engine.rb
111
+ - lib/gakubuchi/fileutils.rb
97
112
  - lib/gakubuchi/task.rb
98
113
  - lib/gakubuchi/template.rb
99
114
  - lib/gakubuchi/version.rb