bgotink-hyde 0.1.0 → 0.2.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: b35e2e38e70e2040272eb73e09c1723addeb037e
4
- data.tar.gz: 649a9dc6e5865353fd824b0bda1d00c371912e09
3
+ metadata.gz: b081f21b5c869455b93b00f9ebe7eff282203e4b
4
+ data.tar.gz: a9cb5777018d9612c8e3ae2128f05c5a833760ca
5
5
  SHA512:
6
- metadata.gz: ba3173c30ede6cba47322d3758b5972f475ba9222ce37fd0ef032c2f5ce4e8ae0bbaf7d6d07c4d54d152776ff53e22ee31cfd040fc7857257eb254b354110d9e
7
- data.tar.gz: ae6bcd9e3c0f1ce2b1d7fd0ce49bc25aaa58d0be1f7d3d26618f2c38430f49ca1bdffd33517dd34988fb4e339ca760a1db06566f118f20387cb2fa5feca6660c
6
+ metadata.gz: eb102e9467d222bb06d68f95132fa58df9ae963497e540fddf7ce179c2c03b84007962a087d707022fe783c7cd408c8fed1b853d018f6b079a628507a1a7f81a
7
+ data.tar.gz: 807d0a1b29aa0f87988260d036239c8ff541eaaf6ef7f87244805f5085c063dc1a2db109debcbd856270c27fce8dd2e6be05a729b0e91efd6eab783a1af35c45
data/History.md CHANGED
@@ -1,4 +1,15 @@
1
- ## HEAD
1
+ ## 0.2.0 / 2014-01-08
2
+
3
+ ### Major Enhancements
4
+ * moved from `map` to `pages` and `posts` in `_config.yml`
5
+ * allow files to be included in `pages` and `posts` directly instead of requiring directories
6
+ * automatically checkout jekyll template from different branch while building
7
+ * also allow destination to be a git branch
8
+
9
+ ### Bugfixes
10
+ * fixed rake release
11
+
12
+ ## 0.1.0 / 2014-01-08
2
13
 
3
14
  ### Major Enhancements
4
15
  * copied and modified gemspec, rakefile etc. from [jekyll](//github.com/jekyll/jekyll)
data/bgotink-hyde.gemspec CHANGED
@@ -4,7 +4,7 @@ Gem::Specification.new do |s|
4
4
  s.rubygems_version = '1.3.5'
5
5
 
6
6
  s.name = 'bgotink-hyde'
7
- s.version = '0.1.0'
7
+ s.version = '0.2.0'
8
8
  s.license = 'MIT'
9
9
  s.date = '2014-01-08'
10
10
  s.rubyforge_project = 'bgotink-hyde'
@@ -59,7 +59,8 @@ Gem::Specification.new do |s|
59
59
  lib/hyde/commands/build.rb
60
60
  lib/hyde/commands/serve.rb
61
61
  lib/hyde/configuration.rb
62
- lib/hyde/jekyllfile.rb
62
+ lib/hyde/page.rb
63
+ lib/hyde/post.rb
63
64
  lib/hyde/site.rb
64
65
  lib/hyde/stevenson.rb
65
66
  ]
data/lib/hyde.rb CHANGED
@@ -10,7 +10,8 @@ def require_all(directory)
10
10
  end
11
11
 
12
12
  require 'hyde/configuration'
13
- require 'hyde/jekyllfile'
13
+ require 'hyde/page'
14
+ require 'hyde/post'
14
15
  require 'hyde/site'
15
16
  require 'hyde/command'
16
17
  require 'hyde/stevenson'
@@ -18,7 +19,7 @@ require 'hyde/stevenson'
18
19
  require_all 'hyde/commands'
19
20
 
20
21
  module Hyde
21
- VERSION = '0.1.0'
22
+ VERSION = '0.2.0'
22
23
 
23
24
  # Public: Generate a Hyde configuration Hash by merging the default
24
25
  # options with anything in _config.yml, and adding the given options on top.
@@ -43,8 +44,8 @@ module Hyde
43
44
  def self.jekyll_configuration(configuration)
44
45
  config = Jekyll::Configuration[Jekyll::Configuration::DEFAULTS]
45
46
  override = Jekyll::Configuration[{
46
- 'source' => configuration['jekyll-out'],
47
- 'destination' => configuration['destination']
47
+ 'source' => configuration['intermediary']['directory'],
48
+ 'destination' => configuration['destination']['directory']
48
49
  }].stringify_keys
49
50
  config = config.read_config_files(config.config_files(override))
50
51
 
@@ -13,9 +13,9 @@ module Hyde
13
13
 
14
14
  def self.build(site, options)
15
15
  source = options['source']
16
- jekyll = options['jekyll']
17
- jekyll_out = options['jekyll-out']
18
- destination = options['destination']
16
+ jekyll = options['template']['directory']
17
+ jekyll_out = options['intermediary']['directory']
18
+ destination = options['destination']['directory']
19
19
 
20
20
  Hyde.logger.info "Source:", source
21
21
  Hyde.logger.info "Jekyll input:", jekyll
@@ -35,13 +35,11 @@ module Hyde
35
35
  # TODO check whether dest is in source?
36
36
 
37
37
  source = options['source']
38
- intermediary = options['jekyll-out']
39
- destination = options['destination']
40
38
 
41
39
  ignored = Array.new
42
- %w[jekyll-out destination].each do |o|
40
+ %w[intermediary destination].each do |o|
43
41
  begin
44
- d = Pathname.new(options[o]).relative_path_from(Pathname.new(source)).to_s
42
+ d = Pathname.new(options[o]['directory']).relative_path_from(Pathname.new(source)).to_s
45
43
  ignored << Regexp.escape(d)
46
44
  rescue ArgumentError
47
45
  # nop
@@ -1,7 +1,8 @@
1
1
  module Hyde
2
2
  module Commands
3
- class Serve < Hyde::Command
3
+ class Serve < Command
4
4
  def self.process(options)
5
+ Hyde.logger.info "Starting server...", ''
5
6
  Jekyll::Commands::Serve.process(Hyde::jekyll_configuration(options))
6
7
  end
7
8
  end
@@ -3,9 +3,18 @@ module Hyde
3
3
 
4
4
  DEFAULTS = {
5
5
  'source' => Dir.pwd,
6
- 'jekyll' => File.join(Dir.pwd, '_jekyll'),
7
- 'jekyll-out' => File.join(Dir.pwd, '_jekyll-out'),
8
- 'destination' => File.join(Dir.pwd, '_site'),
6
+ 'template' => {
7
+ 'directory' => File.join(Dir.pwd, '_template'),
8
+ 'branch' => nil,
9
+ 'update' => true
10
+ },
11
+ 'intermediary' => {
12
+ 'directory' => File.join(Dir.pwd, '_intermediary')
13
+ },
14
+ 'destination' => {
15
+ 'directory' => File.join(Dir.pwd, '_site'),
16
+ 'branch' => nil
17
+ },
9
18
 
10
19
  'keep' => false,
11
20
 
@@ -14,6 +23,9 @@ module Hyde
14
23
  'safe' => false,
15
24
  'detach' => false,
16
25
 
26
+ 'pages' => Hash.new,
27
+ 'posts' => Hash.new,
28
+
17
29
  'port' => Jekyll::Configuration::DEFAULTS['port'],
18
30
  'host' => Jekyll::Configuration::DEFAULTS['host']
19
31
  }
@@ -1,26 +1,38 @@
1
1
  module Hyde
2
2
 
3
- class JekyllFile
4
- attr_accessor :original, :destination
3
+ class Page
4
+ attr_accessor :original, :name, :time
5
5
 
6
6
  def initialize(location, destination)
7
- self.original = File.absolute_path(location)
7
+ @original = File.absolute_path(location)
8
+ @dest_dir = destination
9
+
8
10
  data = read_yaml(self.original)
9
11
 
10
- name = File.basename(location)
11
- time = if data['hyde_date']
12
- Time.parse(data['hyde_date'])
13
- else
14
- File.mtime(location)
15
- end
12
+ @name = File.basename(location)
13
+ @time = if data['hyde_date']
14
+ Time.parse(data['hyde_date'])
15
+ elsif data['date']
16
+ Time.parse(data['date'])
17
+ else
18
+ File.mtime(location)
19
+ end
20
+ end
16
21
 
17
- dest_file_name = "#{time.strftime('%Y-%m-%d')}-#{name}"
22
+ def dest_filename
23
+ name
24
+ end
25
+
26
+ def dest_dir
27
+ @dest_dir
28
+ end
18
29
 
19
- self.destination = File.join(destination, dest_file_name)
30
+ def destination
31
+ File.join(dest_dir, dest_filename)
20
32
  end
21
33
 
22
34
  def write
23
- File.symlink(self.original, self.destination)
35
+ File.symlink(original, destination)
24
36
  end
25
37
 
26
38
  private
data/lib/hyde/post.rb ADDED
@@ -0,0 +1,13 @@
1
+ module Hyde
2
+
3
+ class Post < Page
4
+ def dest_filename
5
+ "#{time.strftime('%Y-%m-%d')}-#{name}"
6
+ end
7
+
8
+ def dest_dir
9
+ File.join(super, '_posts')
10
+ end
11
+ end
12
+
13
+ end
data/lib/hyde/site.rb CHANGED
@@ -1,15 +1,19 @@
1
1
  module Hyde
2
2
 
3
3
  class Site
4
- attr_accessor :config, :map, :source, :jekyll_source, :dest, :time, :files
4
+ attr_accessor :options, :pages, :posts
5
+ attr_accessor :source, :template, :dest
6
+ attr_accessor :time, :files
5
7
 
6
- def initialize(config)
7
- self.config = config
8
+ def initialize(options)
9
+ self.options = options
8
10
 
9
- self.map = config['map'] || {}
10
- self.source = File.expand_path(config['source'])
11
- self.jekyll_source = File.expand_path(config['jekyll'])
12
- self.dest = File.expand_path(config['jekyll-out'])
11
+ self.pages = options['pages']
12
+ self.posts = options['posts']
13
+
14
+ self.source = File.expand_path(options['source'])
15
+ self.template = File.expand_path(options['template']['directory'])
16
+ self.dest = File.expand_path(options['intermediary']['directory'])
13
17
 
14
18
  self.reset
15
19
  self.setup
@@ -26,8 +30,8 @@ module Hyde
26
30
 
27
31
  # reset the time
28
32
  def reset
29
- self.time = if self.config['time']
30
- Time.parse(self.config['time'].to_s)
33
+ self.time = if options['time']
34
+ Time.parse(options['time'].to_s)
31
35
  else
32
36
  Time.now
33
37
  end
@@ -35,95 +39,145 @@ module Hyde
35
39
 
36
40
  # copy Jekyll source files
37
41
  def setup
38
- FileUtils.rm_rf(self.dest)
39
- FileUtils.cp_r(self.jekyll_source, self.dest, :preserve => true)
42
+ if options['destination']['branch']
43
+ clone_directory(options['destination'])
44
+ else
45
+ FileUtils.rm_rf(dest)
46
+ end
47
+
48
+ clone_directory(options['template']) if options['template']['branch']
49
+
50
+ FileUtils.rm_rf(dest)
51
+ FileUtils.cp_r(template, dest, :preserve => true)
40
52
  end
53
+
54
+ private
41
55
 
42
- # create the Hyde-to-Jekyll output directories
43
- def directories
44
- self.map.each do |source_d, dest_d|
45
- source = File.join(self.source, source_d)
46
- if File.exists?(source)
47
- dest = File.join(self.dest, dest_d)
48
- if File.exists?(dest)
49
- Hyde.logger.abort_with 'Illegal file:' "Expected destination file #{dest_d}/_posts to be a directory but found a file" unless File.directory?(dest)
50
- Hyde.logger.warn 'Destination exists:', "Destination directory #{dest_d} exists, deleting content" unless self.config['watching']
51
-
52
- Dir[File.join(dest, '*')].each do |f|
53
- FileUtils.rm_rf(f)
54
- end
55
- else
56
- FileUtils.mkdir_p(dest)
56
+ def clone_directory(options)
57
+ directory = options['directory']
58
+ branch = options['branch']
59
+ update = (options['update'] == true || options['update'] == 'true')
60
+
61
+ unless File.directory?('.git')
62
+ Hyde.logger.abort_with "Not a git repo:", "The current directory is not a git repository."
63
+ end
64
+
65
+ if File.exists?(directory)
66
+ if File.directory?(directory)
67
+ # if git: cd && git pull
68
+ if File.directory?(File.join(directory, '.git')) and update
69
+ Hyde.logger.info 'Updating directory:', "Pulling branch #{branch} in #{directory}..."
70
+ `cd #{directory} && git pull`
71
+ Hyde.logger.info '', 'done'
72
+ elsif update
73
+ Hyde.logger.warn 'Expected git repo:', "Expected #{directory} to be a git repo"
74
+ Hyde.logger.warn '', 'as a branch was supplied to pull from.'
57
75
  end
58
76
  else
59
- Hyde.logger.warn 'File not found:', "Directory #{source_d} does not exist, skipping directory"
77
+ Hyde.logger.abort_with 'Expected directory:', "#{directory} but found file"
60
78
  end
79
+ else
80
+ Hyde.logger.info 'Cloning template:', "Cloning branch #{branch} into #{directory}..."
81
+ `git new-workdir . #{directory} #{branch}`
82
+ Hyde.logger.info '', 'done.'
61
83
  end
62
84
  end
63
85
 
64
- # read files
65
- def read
66
- self.files ||= Hash.new
67
- self.map.each do |source_d, dest_d|
68
- files = Hash.new
69
- Hyde.logger.error 'Duplicate source:', "directory \"#{source_d}\"" if self.files[source_d]
70
- self.files[source_d] = files
71
-
72
- read_directory(source_d, files, File.join(self.dest, dest_d))
73
- end
86
+ public
87
+
88
+ # create the Hyde-to-Jekyll output directories
89
+ def directories
90
+ directories_helper(pages)
91
+ directories_helper(posts, '_posts')
74
92
  end
75
93
 
76
94
  private
77
95
 
78
- def read_directory(directory, data, destination)
79
- Dir[File.join(directory, '*')].sort.each do |file|
80
- if File.directory?(file)
81
- fdata = Hash.new
82
- read_directory(file, fdata, destination)
83
- data[File.basename(file)] = fdata
84
- else
85
- data[File.basename(file)] = JekyllFile.new(file, destination)
96
+ def directories_helper(data, dest_suffix = '')
97
+ data.each do |source, dest|
98
+ source = File.join(self.source, source)
99
+ dest = File.join(self.dest, dest, dest_suffix)
100
+
101
+ unless File.exists?(source)
102
+ Hyde.logger.warn 'File not found:', "File/directory #{source} does not exist, skipping"
103
+ return
104
+ end
105
+
106
+ if File.exists?(dest)
107
+ unless File.directory?(source) == File.directory?(dest)
108
+ Hyde.logger.abort_with 'Illegal file:', "Expected #{dest} to be a #{File.directory?(source) ? 'directory but found file.' : 'file but found directory.'}"
109
+ end
110
+
111
+ FileUtils.rm_rf(dest)
112
+ end
113
+
114
+ # if directory: create directory, otherwise nop
115
+ if File.directory?(source)
116
+ FileUtils.mkdir_p(dest)
86
117
  end
87
118
  end
88
119
  end
89
120
 
90
121
  public
91
122
 
92
- # write jekyll files
93
- def write
94
- self.files.each do |name, files|
95
- write_recursive(files, File.join(self.dest, self.map[name]))
123
+ # read files
124
+ def read
125
+ self.files ||= Array.new
126
+
127
+ read_files(pages) do | source, destination |
128
+ files << Page.new(source, File.join(self.dest, destination))
129
+ end
130
+ read_files(posts) do | source, destination |
131
+ files << Post.new(source, File.join(self.dest, destination))
96
132
  end
97
133
  end
98
134
 
99
135
  private
100
136
 
101
- def write_recursive(files, directory)
102
- files.each do |name, file|
103
- if file.is_a?(JekyllFile)
104
- file.write
137
+ def read_files(files)
138
+ files.each do | source, destination |
139
+ if File.directory?(source)
140
+ read_directory(source, destination) { |s,d| yield(s,d) }
105
141
  else
106
- write_recursive(file, directory)
142
+ yield(source, destination)
143
+ end
144
+ end
145
+ end
146
+
147
+ def read_directory(directory, destination)
148
+ Dir[File.join(directory, '*')].sort.each do |source|
149
+ if File.directory?(source)
150
+ read_directory(source, destination) { |s,d| yield(s,d) }
151
+ else
152
+ yield(source, destination)
107
153
  end
108
154
  end
109
155
  end
110
156
 
111
157
  public
112
158
 
159
+ # write jekyll files
160
+ def write
161
+ files.each do |file|
162
+ file.write
163
+ end
164
+ end
165
+
113
166
  # cleanup
114
167
  def cleanup
115
- self.files = Hash.new
116
- FileUtils.rm_rf(self.dest) unless self.config['keep'] or self.config['watching']
168
+ self.files = Array.new
169
+ FileUtils.rm_rf(self.dest) unless options['keep'] or options['watching'] or options['serving']
117
170
  end
118
171
 
119
172
  # runs Jekyll
120
173
  def build
121
174
  jekyll_options = Hash.new
122
175
 
123
- %w[safe destination verbose].each do |c|
124
- jekyll_options[c] = self.config[c] if self.config[c]
176
+ %w[safe verbose].each do |c|
177
+ jekyll_options[c] = options[c] if options[c]
125
178
  end
126
179
 
180
+ jekyll_options['destination'] = options['destination']['directory']
127
181
  jekyll_options['source'] = self.dest
128
182
 
129
183
  jekyll_options = Jekyll::configuration(jekyll_options)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bgotink-hyde
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bram Gotink
@@ -102,7 +102,8 @@ files:
102
102
  - lib/hyde/commands/build.rb
103
103
  - lib/hyde/commands/serve.rb
104
104
  - lib/hyde/configuration.rb
105
- - lib/hyde/jekyllfile.rb
105
+ - lib/hyde/page.rb
106
+ - lib/hyde/post.rb
106
107
  - lib/hyde/site.rb
107
108
  - lib/hyde/stevenson.rb
108
109
  homepage: http://github.com/bgotink/hyde