mr_hyde 0.3.1 → 0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d2470400bbbda23e77dcfe015b21bdd987278cbd
4
- data.tar.gz: 2718ceeb1774698fd22038c0d30f733d0a2cc58b
3
+ metadata.gz: a63482aba4bba186b23e2b66afebbdc360d9085c
4
+ data.tar.gz: ce48375f3b63ff83d6c0efb4262f261d67ac925d
5
5
  SHA512:
6
- metadata.gz: 59c238a5502a218ed2ac749bed0c7af83099c911aaca45554a73fa433250c7db42e57f6c46f3be65463c0a92aebee7f4a562637545c3ec6551dc2b621df8ce16
7
- data.tar.gz: b79d839ad2d973a63768964da00542a1caf6caa35b1358a37d9ef31ca9a8519d0df36b818304138236ffeb7aa46c0bdcd1ed2cb8b9ab912ec3dc89fe4c3d675c
6
+ metadata.gz: 48e67b1184d55d5ae23d686004a613774e3d48c960377788c95290ac63b5c6537ff87aa526f388f461753ac444f2a2a75a37e89825d73f2ceb597db5b2b3797d
7
+ data.tar.gz: 39e1794f3841c515bd1a5999298b6531726f54230bf37b8610ad0ad41288e61a2161933daeb9722b992abb8930862b27086a4102d88a92e8da4a818c47c424cf
data/bin/mrhyde CHANGED
@@ -30,12 +30,38 @@ end
30
30
  def cmd_build(command)
31
31
  command.option "all", "--all", "Builds main site and nested sites. Not applied when building a nested site."
32
32
 
33
+ add_build_options(command)
34
+
33
35
  command.action do |args, options|
34
36
  options['main'] = true if args.length == 0
35
37
  MrHyde::Commands::Build.process args, options
36
38
  end
37
39
  end
38
40
 
41
+ # Add common options to a command for building configuration
42
+ #
43
+ # c - the Jekyll::Command to add these options to
44
+ #
45
+ # Returns nothing
46
+ def add_build_options(c)
47
+ c.option 'config', '--config CONFIG_FILE[,CONFIG_FILE2,...]', Array, 'Custom configuration file'
48
+ c.option 'quiet', '-q', '--quiet', 'Silence output.'
49
+ c.option 'verbose', '-V', '--verbose', 'Print verbose output.'
50
+ =begin
51
+ c.option 'destination', '-d', '--destination DESTINATION', 'The current folder will be generated into DESTINATION'
52
+ c.option 'source', '-s', '--source SOURCE', 'Custom source directory'
53
+ c.option 'future', '--future', 'Publishes posts with a future date'
54
+ c.option 'limit_posts', '--limit_posts MAX_POSTS', Integer, 'Limits the number of posts to parse and publish'
55
+ c.option 'watch', '-w', '--[no-]watch', 'Watch for changes and rebuild'
56
+ c.option 'force_polling', '--force_polling', 'Force watch to use polling'
57
+ c.option 'lsi', '--lsi', 'Use LSI for improved related posts'
58
+ c.option 'show_drafts', '-D', '--drafts', 'Render posts in the _drafts folder'
59
+ c.option 'unpublished', '--unpublished', 'Render posts that were marked as unpublished'
60
+ c.option 'verbose', '-V', '--verbose', 'Print verbose output.'
61
+ c.option 'incremental', '-I', '--incremental', 'Enable incremental rebuild.'
62
+ =end
63
+ end
64
+
39
65
  Mercenary.program(:mrhyde) do |p|
40
66
  p.version MrHyde::VERSION
41
67
  p.description "Mr. Hyde is a tool intended to manage as many blog as you want powered by Jekyll."
data/lib/mr_hyde.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "fileutils"
2
+ require "pathname"
2
3
  require "logger"
3
4
 
4
5
  require "jekyll/log_adapter"
@@ -36,24 +37,26 @@ module MrHyde
36
37
  end
37
38
 
38
39
  # Jekyll Configuration
39
- def main_site_configuration
40
+ def main_site_configuration(opts = nil)
40
41
  # The order is important here, the last one overrides the previous ones
41
- site_configuration nil
42
+ site_configuration nil, opts
42
43
  end
43
44
 
44
45
  # Jekyll per site configuration
45
46
  # This method gets the config files which must be read from jekyll.
46
47
  # _config.yml < sites/site/_config.yml < override
47
48
  #
48
- def site_configuration(site_name = nil)
49
+ def site_configuration(site_name = nil, opts_args = nil)
50
+ clone_opts_args = opts_args.clone if opts_args
49
51
  jekyll_config = jekyll_defaults(site_name)
50
52
  site_name ||= config['mainsite']
51
53
  opts = {}
52
54
 
53
55
  # The order is important here, the last one overrides the previous one
54
56
  opts['config'] = []
55
- opts['config'] << Jekyll.sanitized_path(source, config['jekyll_config']) if has_jekyll_config?
57
+ opts['config'] << Jekyll.sanitized_path(source, config['config']) if has_jekyll_config?
56
58
  opts['config'] << Site.custom_config(site_name, config) if Site.has_custom_config?(site_name, config)
59
+ opts['config'].concat(Configuration[Configuration::DEFAULTS].config_files(clone_opts_args)) if clone_opts_args and clone_opts_args['config']
57
60
 
58
61
  jekyll_config.merge(opts)
59
62
  end
@@ -63,18 +66,18 @@ module MrHyde
63
66
  conf = if site_name
64
67
  { 'baseurl' => '/' + site_name,
65
68
  'destination' => File.join(MrHyde.destination, site_name),
66
- 'source' => File.join(MrHyde.sources_sites, site_name) }
69
+ 'source' => Pathname.pwd.join(MrHyde.sources_sites, site_name).to_s }
67
70
  else
68
71
  site_name = config['mainsite']
69
- { 'source' => File.join(site_name),
70
- 'destination' => File.join(MrHyde.destination) }
72
+ { 'source' => Pathname.pwd.join(site_name).to_s,
73
+ 'destination' => File.join(MrHyde.destination).to_s }
71
74
  end
72
75
 
73
76
  conf.merge({ 'layouts_dir' => File.join(config['layouts_dir']) })
74
77
  end
75
78
 
76
79
  def has_jekyll_config?
77
- File.exist? File.expand_path(File.join(source, @config['jekyll_config']))
80
+ File.exist? File.expand_path(File.join(source, @config['config']))
78
81
  end
79
82
 
80
83
  def sources_sites
@@ -93,7 +96,7 @@ module MrHyde
93
96
  #
94
97
  # Returns the LogAdapter instance.
95
98
  def logger
96
- @logger = LogAdapter.new(Stevenson.new, (ENV['MRHYDE_LOG_LEVEL'] || :info).to_sym)
99
+ @logger ||= LogAdapter.new(Stevenson.new, (ENV['MRHYDE_LOG_LEVEL'] || :info).to_sym)
97
100
  end
98
101
 
99
102
  def logger=(writer)
@@ -12,6 +12,7 @@ module MrHyde
12
12
  class << self
13
13
  # Options
14
14
  def process(args, opts = {})
15
+ MrHyde.logger.adjust_verbosity opts
15
16
  MrHyde::Site.build args, opts
16
17
  MrHyde.logger.info "Built process is finished, you can see the result in '#{MrHyde.destination}' folder"
17
18
  end
@@ -8,12 +8,16 @@ module MrHyde
8
8
  'source' => Dir.pwd,
9
9
  'destination' => 'site',
10
10
  'sources_sites' => '_sites',
11
- 'config' => '_mrhyde.yml',
12
- 'jekyll_config' => '_config.yml',
11
+ 'config' => '_config.yml',
13
12
  'assets' => '_assets',
14
13
  'mainsite' => '_site'
15
14
  })
16
15
 
16
+ def config_files(override)
17
+ MrHyde.logger.adjust_verbosity(:quiet => quiet?(override), :verbose => verbose?(override))
18
+ super(override)
19
+ end
20
+
17
21
  def read_config_files(files)
18
22
  configuration = clone
19
23
 
data/lib/mr_hyde/site.rb CHANGED
@@ -14,6 +14,7 @@ module MrHyde
14
14
  File.join MrHyde.source, MrHyde.sources_sites
15
15
  end
16
16
  yield if block_given?
17
+ opts
17
18
  end
18
19
 
19
20
  # Creates the directory and necessary files for the site
@@ -83,8 +84,8 @@ module MrHyde
83
84
  def build(args = nil, opts = {})
84
85
  init(args, opts)
85
86
 
86
- # If there is no destinarion folder then will be created
87
- mk_destination(opts) unless File.exist? MrHyde.destination
87
+ # If there is no destination folder then will be created
88
+ #mk_destination(opts) unless File.exist? MrHyde.destination
88
89
 
89
90
  if not args.nil? and not args.empty?
90
91
  build_sites args, opts
@@ -150,13 +151,19 @@ module MrHyde
150
151
  end
151
152
 
152
153
  def custom_config(name, opts)
153
- File.join site_path(name), opts['jekyll_config']
154
+ File.join site_path(name), opts['config']
154
155
  end
155
156
 
156
157
  def is_main?(name)
157
158
  File.directory? File.join(name)
158
159
  end
159
160
 
161
+ # Receives an array of files don't want to be removed
162
+ def keep_files(files, conf)
163
+ conf['keep_files'] = [] unless conf['keep_files']
164
+ conf['keep_files'] = conf['keep_files'].concat(files).uniq
165
+ end
166
+
160
167
  private
161
168
 
162
169
  def create_site(args, opts = {})
@@ -212,25 +219,25 @@ module MrHyde
212
219
  end
213
220
  end
214
221
 
215
- def build_site(name, opts)
216
- conf = MrHyde.site_configuration(name)
222
+ def build_site(name, opts = nil)
223
+ conf = MrHyde.site_configuration(name, opts)
217
224
  Jekyll::Commands::Build.process conf
218
225
  MrHyde.logger.info "#{name} built in #{MrHyde.destination}"
219
226
  built? name, opts
220
227
  end
221
228
 
222
- def build_main_site(opts)
223
- conf = MrHyde.main_site_configuration
229
+ def build_main_site(opts = nil)
230
+ conf = MrHyde.main_site_configuration opts
224
231
  keep_built_sites conf
225
232
  Jekyll::Commands::Build.process conf
226
233
  end
227
234
 
228
235
  def keep_built_sites(conf)
229
- conf['keep_files'] = built_list
236
+ keep_files built_list, conf
230
237
  end
231
238
 
232
239
  def mk_destination(opts)
233
- conf = MrHyde.main_site_configuration
240
+ conf = MrHyde.main_site_configuration opts
234
241
  Dir.mkdir conf["destination"]
235
242
  end
236
243
 
@@ -1,3 +1,3 @@
1
1
  module MrHyde
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -8,7 +8,9 @@ description: > # this means to ignore newlines until "baseurl:"
8
8
  line in _config.yml. It will appear in your document head meta (for
9
9
  Google search results) and in your feed.xml site description.
10
10
  baseurl: "" # the subpath of your site, e.g. /blog/
11
- mainsite: "_site" # this is the name of the root default site, where all sites will be nested
12
11
  url: "http://yourdomain.com" # the base hostname & protocol for your site
13
12
  twitter_username: mrhyderb
14
13
  github_username: mrhyde
14
+
15
+ # Mr. Hyde settings
16
+ mainsite: "_site" # this is the name of the root default (main) site, where all sites will be nested
data/mr_hyde.gemspec CHANGED
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
23
  spec.add_development_dependency "minitest", "~> 5.8", ">= 5.8.4"
24
24
  spec.add_development_dependency "minitest-reporters", "~> 1.1", ">= 1.1.7"
25
+ spec.add_development_dependency "nokogiri", "~> 1.6.7"
25
26
  spec.add_development_dependency "pry"
26
27
  spec.add_development_dependency "byebug", "~> 8.2.2"
27
28
 
data/spec/build_spec.rb CHANGED
@@ -1,8 +1,12 @@
1
1
  require "minitest/autorun"
2
2
  require "minitest/reporters"
3
+ require "nokogiri"
3
4
  require "fileutils"
5
+ require "pathname"
6
+ require "yaml"
4
7
  require_relative "../lib/mr_hyde"
5
8
  require_relative "../lib/mr_hyde/site"
9
+ require_relative "../lib/mr_hyde/commands/build"
6
10
 
7
11
  Minitest::Reporters.use! [Minitest::Reporters::SpecReporter.new, Minitest::Reporters::ProgressReporter.new]
8
12
 
@@ -62,4 +66,49 @@ describe "Checking MrHyde build command" do
62
66
  end
63
67
  end
64
68
 
69
+ describe "specifying another configuration file" do
70
+ def test_for_error
71
+ yield
72
+ 'ok'
73
+ rescue
74
+ $!
75
+ end
76
+
77
+ def fetch_title
78
+ # Checking the title provided by the new config file
79
+ html_file = Pathname.pwd.join(MrHyde.configuration['destination'], 'index.html')
80
+ doc = Nokogiri::HTML Pathname.new(html_file)
81
+ res = doc.search '.row hgroup h1.site-title a'
82
+ res.children.first.to_s
83
+ end
84
+
85
+ before do
86
+ @current_file = Pathname.new(Dir.pwd).join MrHyde.configuration['config']
87
+ @yml_file = YAML.load_file @current_file
88
+ @yml_file['title'] = "Copied file title"
89
+ @new_file = Pathname.pwd.join("..").join(@current_file.basename)
90
+
91
+ File.open(@new_file.to_s, "w") do |f|
92
+ f.write @yml_file.to_yaml
93
+ end
94
+ end
95
+
96
+ it "can build site when --config option is used" do
97
+ # Building site
98
+ test_for_error do
99
+ MrHyde::Site.build([], {'config' => @new_file.to_s})
100
+ end.must_equal 'ok'
101
+
102
+ fetch_title().must_equal @yml_file['title']
103
+ end
104
+
105
+ it "can build all sites with --config and --all option" do
106
+ # Building site
107
+ test_for_error do
108
+ MrHyde::Site.build([], {'config' => @new_file.to_s, 'all' => true})
109
+ end.must_equal 'ok'
110
+
111
+ fetch_title().must_equal @yml_file['title']
112
+ end
113
+ end
65
114
  end
data/spec/new_spec.rb CHANGED
@@ -21,7 +21,6 @@ describe "Checking if mrhyde can create new sites" do
21
21
  MrHyde.create
22
22
 
23
23
  File.exist?(File.join '.', @defaults['config']).must_be :==, true
24
- File.exist?(File.join '.', @defaults['jekyll_config']).must_be :==, true
25
24
  File.exist?(File.join '.', @defaults['layouts_dir']).must_be :==, true
26
25
  File.exist?(File.join '.', @defaults['includes_dir']).must_be :==, true
27
26
  File.exist?(File.join '.', @defaults['assets']).must_be :==, true
@@ -36,7 +35,6 @@ describe "Checking if mrhyde can create new sites" do
36
35
  File.exist?(@site_name).must_be :==, true
37
36
  File.exist?(File.join @site_name).must_be :==, true
38
37
  File.exist?(File.join @site_name, @defaults['config']).must_be :==, true
39
- File.exist?(File.join @site_name, @defaults['jekyll_config']).must_be :==, true
40
38
  File.exist?(File.join @site_name, @defaults['layouts_dir']).must_be :==, true
41
39
  File.exist?(File.join @site_name, @defaults['includes_dir']).must_be :==, true
42
40
  File.exist?(File.join @site_name, @defaults['assets']).must_be :==, true
@@ -51,7 +49,6 @@ describe "Checking if mrhyde can create new sites" do
51
49
  File.exist?(@site_name).must_be :==, true
52
50
  File.exist?(File.join @site_name).must_be :==, true
53
51
  File.exist?(File.join @site_name, @defaults['config']).must_be :==, false
54
- File.exist?(File.join @site_name, @defaults['jekyll_config']).must_be :==, false
55
52
  File.exist?(File.join @site_name, @defaults['layouts_dir']).must_be :==, true
56
53
  File.exist?(File.join @site_name, @defaults['includes_dir']).must_be :==, true
57
54
  File.exist?(File.join @site_name, @defaults['assets']).must_be :==, false
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mr_hyde
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Enrique Arias Cervero
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-19 00:00:00.000000000 Z
11
+ date: 2016-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -78,6 +78,20 @@ dependencies:
78
78
  - - ">="
79
79
  - !ruby/object:Gem::Version
80
80
  version: 1.1.7
81
+ - !ruby/object:Gem::Dependency
82
+ name: nokogiri
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - "~>"
86
+ - !ruby/object:Gem::Version
87
+ version: 1.6.7
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - "~>"
93
+ - !ruby/object:Gem::Version
94
+ version: 1.6.7
81
95
  - !ruby/object:Gem::Dependency
82
96
  name: pry
83
97
  requirement: !ruby/object:Gem::Requirement
@@ -191,7 +205,6 @@ files:
191
205
  - lib/site_template/_layouts/default.html
192
206
  - lib/site_template/_layouts/page.html
193
207
  - lib/site_template/_layouts/post.html
194
- - lib/site_template/_mrhyde.yml
195
208
  - lib/site_template/_site/about.md
196
209
  - lib/site_template/_site/css/main.scss
197
210
  - lib/site_template/_site/css/normalize.css
@@ -1,2 +0,0 @@
1
- # Mr. Hyde settings
2
- mainsite: "_site" # this is the name of the root default site, where all sites will be nested