usmu 0.3.2 → 0.3.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: 82edd4386ce8ad7e313db42fcb53ae4b908f8988
4
- data.tar.gz: bf0bbc5db654e595fccfaa5d65965976d2d2b75d
3
+ metadata.gz: a5993d2cf7f8ba77f906f2fdca5ea2bd0d7f8368
4
+ data.tar.gz: 17e1c5a84df4715b6042c79fefe3ea66966b089b
5
5
  SHA512:
6
- metadata.gz: 19a6e9d124cefab1e4068b5c29da0eb1656cf7e10bf844e5b7ae29fc03d7e39966e5d11785a13fdf28eeb8e6d7d14f5acf41c37cda6cf51dbdc5d9b99df24860
7
- data.tar.gz: 181da46641fa0d63e0359f069bba71d2deca24fac77fb03ee801be16bebc769361d3c5fd4584023f039a38616b24c52d32a198f52fc4f5e515eac0823cc6f187
6
+ metadata.gz: 5ff5e410972c66371dfbef17b8fcac40371f1624ce93d1679cc3bc1bd77501d3827f2a45a9b97141be01775367054ce9f2481959cc79a59ae270a21cd195ddef
7
+ data.tar.gz: d855520486e29adc40c4f2a33688be8cb0348d5aa8714372c3aba965eb1be0f89a060819891d4b76492144085b221848c0bc517db46f626a3d395628ccdcd4e4
@@ -6,22 +6,18 @@ rvm:
6
6
  - 2.1
7
7
  - 2.2
8
8
  - ruby-head
9
- - mruby-head
10
- - rbx-2.1
11
- - rbx-2.2
12
- - rbx-2.3
9
+ #- mruby-head
10
+ #- rbx-2.1
11
+ #- rbx-2.2
12
+ #- rbx-2.3
13
13
  - rbx-2.4
14
+ - jruby
15
+ - jruby-head
14
16
  matrix:
15
17
  include:
16
18
  - rvm: jruby
17
- gemfile: Gemfile-jruby
18
- - rvm: jruby
19
- gemfile: Gemfile-jruby
20
19
  env: JRUBY_OPTS='--2.0'
21
20
  - rvm: jruby-head
22
- gemfile: Gemfile-jruby
23
- - rvm: jruby-head
24
- gemfile: Gemfile-jruby
25
21
  env: JRUBY_OPTS='--2.0'
26
22
  allow_failures:
27
23
  - rvm: 1.9.3
@@ -1,5 +1,23 @@
1
1
  # Usmu Change Log
2
2
 
3
+ ## 0.3.3
4
+
5
+ Matthew Scharley <matt.scharley@gmail.com>
6
+
7
+ * Disallow mutant on 2.2 (f6afd151d54c8fefb6a9af68a7cea1bae8f32265)
8
+ * Cleanup gem builds to use the same gemspec (48cce89d6936e0b0668bf9714989d786ac573aaf)
9
+ * Cleanup Travis since we don't need includes (as much) (8453421218e0b63755bccae6b2e01754225bbe7a)
10
+ * [skip ci] Add a minimum Ruby requirement (c90711ac1e41c8a9973e987aa308a88c951e05dc)
11
+ * Hopefully fix rbx (e6a51d07986b4347394ae3b571bb6b2a16ad1db3)
12
+ * [skip ci] minor cleanup (662e0e6e82aa01fe0883e794dc9fea0407dfdadc)
13
+ * [#15][#16] Add an example of directory metadata and static parsing (b369fdde02a5b7c25f60e86fabc248a448b68b19)
14
+ * [#15] Add directory metadata (66dd094ffdcafb8ecced06a9ad7c578b64885689)
15
+ * [#16] add a metadata value to force static parsing (02dc5794f9dc3efc2655d375cd2dd17c45e8cea7)
16
+ * Fix minor regression from #15 (e179fd27d133d647d7025d82a697e6d1f202224b)
17
+ * [#21] Add some ignored classes for mutant (0bf4a328e6aebf87ed489bcf3d6f19ea111fa95e)
18
+ * [#21] Cover Usmu::Deployment::DirectoryDiff (d4836b1ddb950223786e35b024e2692e106a2c41)
19
+ * [#18] Initialise logging before commander (6117299b6303b54249c06d894e074cbb437623c2)
20
+
3
21
  ## 0.3.2
4
22
 
5
23
  Matthew Scharley <matt.scharley@gmail.com>
data/Gemfile CHANGED
@@ -1,11 +1,20 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ unless ENV['BUILD_PLATFORM']
4
+ ENV['BUILD_PLATFORM'] = case RUBY_ENGINE
5
+ when 'jruby'
6
+ 'java'
7
+ else
8
+ 'ruby'
9
+ end
10
+ end
11
+
3
12
  # Specify your gem's dependencies in usmu.gemspec
4
13
  gemspec name: 'usmu'
5
14
 
6
15
  gem 'codeclimate-test-reporter', group: :test, require: nil
7
16
 
8
- if RUBY_VERSION.to_f >= 2
17
+ if RUBY_VERSION.to_f >= 2 && RUBY_VERSION.to_f < 2.2 && RUBY_ENGINE == 'ruby'
9
18
  gem 'mutant', '~> 0.7'
10
19
  gem 'mutant-rspec', '~> 0.7'
11
20
  end
data/Guardfile CHANGED
@@ -4,8 +4,8 @@
4
4
  guard :rspec, cmd: 'rspec', spec_paths: ['spec'] do
5
5
  watch(%r{^spec/.+_spec\.rb$})
6
6
  watch(%r{^lib/usmu/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
7
- watch(%r{^test/spec/support}) { 'spec' }
8
- watch('test/spec/spec_helper.rb') { 'spec' }
7
+ watch(%r{^spec/support}) { 'spec' }
8
+ watch('spec/spec_helper.rb') { 'spec' }
9
9
 
10
10
  # Turnip features and steps
11
11
  watch(%r{^spec/acceptance/(.+)\.feature$})
data/Rakefile CHANGED
@@ -8,13 +8,17 @@ def current_gems
8
8
  Dir["pkg/usmu-#{Usmu::VERSION}*.gem"].sort_by &:length
9
9
  end
10
10
 
11
+ def platforms
12
+ %w(ruby java)
13
+ end
14
+
11
15
  RSpec::Core::RakeTask.new(:spec) do |t|
12
16
  t.pattern = 'spec'
13
17
  end
14
18
 
15
19
  desc 'Start an IRB session with local code available'
16
20
  task :irb do
17
- exec 'bundle', 'exec', 'irb', '-I', 'lib'
21
+ exec *%w{bundle exec irb}
18
22
  end
19
23
 
20
24
  desc 'Run all test scripts'
@@ -26,7 +30,15 @@ task :mutant, [:target] => [:clean] do |t,args|
26
30
  if `which mutant 2>&1 > /dev/null; echo \$?`.to_i != 0
27
31
  puts 'Mutant isn\'t supported on your platform. Please run these tests on MRI <= 2.1.5.'
28
32
  else
29
- sh('bundle', 'exec', 'mutant', '--include', 'lib', '--require', 'usmu', '--use', 'rspec', args[:target] || 'Usmu*')
33
+ sh 'bundle', 'exec', 'mutant',
34
+ '--include', 'lib',
35
+ '--require', 'usmu',
36
+ '--require', 'usmu/deployment',
37
+ '--use', 'rspec',
38
+ # Interfaces and documentation classes
39
+ '--ignore-subject', 'Usmu::Deployment::RemoteFileInterface*',
40
+ '--ignore-subject', 'Usmu::Plugin::CoreHooks*',
41
+ args[:target] || 'Usmu*'
30
42
  end
31
43
  ENV['CODECLIMATE_REPO_TOKEN'] = old unless old.nil?
32
44
  end
@@ -38,8 +50,7 @@ desc 'Clean up after tests'
38
50
  task :clean do
39
51
  [
40
52
  'tmp',
41
- 'test/coverage',
42
- 'test/site/site',
53
+ 'test-site/site',
43
54
  current_gems,
44
55
  ].flatten.each do |f|
45
56
  rm_r f if File.exist? f
@@ -49,9 +60,16 @@ end
49
60
  namespace :gem do
50
61
  desc 'Build gems'
51
62
  task :build => [:clean] do
63
+ if ENV['BUNDLE_GEMFILE']
64
+ STDERR.puts 'This command will fail if run via bundler. If you are using RVM, please try running the following command:'
65
+ STDERR.puts " NOEXEC_DISABLE=1 #{File.basename($0)} #{ARGV.join(' ')}"
66
+ exit 1
67
+ end
68
+
52
69
  mkdir 'pkg' unless File.exist? 'pkg'
53
- Dir['*.gemspec'].each do |gemspec|
54
- sh "gem build #{gemspec}"
70
+ platforms.each do |p|
71
+ ENV['BUILD_PLATFORM'] = p
72
+ sh *%w{gem build usmu.gemspec}
55
73
  end
56
74
  Dir['*.gem'].each do |gem|
57
75
  mv gem, "pkg/#{gem}"
@@ -61,18 +79,18 @@ namespace :gem do
61
79
  desc 'Install gem'
62
80
  task :install => ['gem:build'] do
63
81
  if RUBY_PLATFORM == 'java'
64
- sh "gem install pkg/usmu-#{Usmu::VERSION}-java.gem"
82
+ sh *%W{gem install pkg/usmu-#{Usmu::VERSION}-java.gem}
65
83
  else
66
- sh "gem install pkg/usmu-#{Usmu::VERSION}.gem"
84
+ sh *%W{gem install pkg/usmu-#{Usmu::VERSION}.gem}
67
85
  end
68
86
  end
69
87
 
70
88
  desc 'Deploy gems to rubygems'
71
89
  task :deploy => ['gem:build'] do
72
90
  current_gems.each do |gem|
73
- sh "gem push #{gem}"
91
+ sh *%W{gem push #{gem}}
74
92
  end
75
- sh "git tag #{Usmu::VERSION}" if File.exist? '.git'
93
+ sh *%W{git tag #{Usmu::VERSION}} if File.exist? '.git'
76
94
  end
77
95
  end
78
96
 
@@ -75,6 +75,7 @@ end
75
75
  %W{
76
76
  usmu/version
77
77
  usmu/configuration
78
+ usmu/metadata_service
78
79
  usmu/site_generator
79
80
  usmu/plugin
80
81
  usmu/plugin/core
@@ -1,4 +1,5 @@
1
1
  require 'yaml'
2
+ require 'usmu/metadata_service'
2
3
 
3
4
  module Usmu
4
5
  # This class is used to represent a configuration file. This file should be a YAML file and called `usmu.yml`
@@ -41,6 +42,10 @@ module Usmu
41
42
  get_files source_path
42
43
  end
43
44
 
45
+ def source_metadata
46
+ @source_metadata ||= MetadataService.new(source_path)
47
+ end
48
+
44
49
  # @!attribute [r] destination_path
45
50
  # @return [String] the full path to the destination folder
46
51
  def destination_path
@@ -59,6 +64,10 @@ module Usmu
59
64
  get_files layouts_path
60
65
  end
61
66
 
67
+ def layouts_metadata
68
+ @layouts_metadata ||= MetadataService.new(layouts_path)
69
+ end
70
+
62
71
  # @!attribute [r] layouts_path
63
72
  # @return [String] the full path to the layouts folder
64
73
  def includes_path
@@ -71,6 +80,10 @@ module Usmu
71
80
  get_files includes_path
72
81
  end
73
82
 
83
+ def includes_metadata
84
+ @includes_metadata ||= MetadataService.new(includes_path)
85
+ end
86
+
74
87
  # An index accessor to directly access the configuration file. It should be noted that `['source']` and
75
88
  # `#source_path` and other similar pairs will have different values. `['source']` is the raw value from the
76
89
  # configuration file while the latter is a path on the system, potentially altered by the path from the current
@@ -161,7 +174,7 @@ module Usmu
161
174
  def get_files(directory)
162
175
  Dir["#{directory}/**/{*,.??*}"].
163
176
  select {|f| not File.directory? f }.
164
- select {|f| !f.match(/\.meta.yml$/) }.
177
+ select {|f| !f.match(/[\.\/]meta\.yml$/) }.
165
178
  map {|f| f[directory.length + 1, f.length] }.
166
179
  select {|f| not excluded? f }
167
180
  end
@@ -31,12 +31,15 @@ module Usmu
31
31
 
32
32
  private
33
33
 
34
+ attr_reader :configuration
35
+ attr_reader :remote_files
36
+
34
37
  def filter_files(f)
35
38
  lstat = File.stat("#{@configuration.destination_path}/#{f}")
36
39
  rstat = @remote_files.stat(f)
37
40
  lhash = File.read("#{@configuration.destination_path}/#{f}")
38
41
 
39
- hash_comparison = check_hash(lhash, rstat)
42
+ hash_comparison = !check_hash(lhash, rstat)
40
43
  time_comparison = lstat.mtime > rstat[:mtime]
41
44
 
42
45
  time_comparison || hash_comparison
@@ -45,18 +48,18 @@ module Usmu
45
48
  def check_hash(lhash, rstat)
46
49
  if not rstat[:md5].nil?
47
50
  rhash = rstat[:md5]
48
- Digest::MD5.hexdigest(lhash) != rhash
51
+ Digest::MD5.hexdigest(lhash).eql? rhash
49
52
  elsif not rstat[:sha1].nil?
50
53
  rhash = rstat[:sha1]
51
- Digest::SHA1.hexdigest(lhash) != rhash
54
+ Digest::SHA1.hexdigest(lhash).eql? rhash
52
55
  else
53
- false
56
+ true
54
57
  end
55
58
  end
56
59
 
57
60
  def local_files_list
58
61
  Dir[@configuration.destination_path + '/**/{*,.??*}'].map do |f|
59
- f[(@configuration.destination_path.length + 1)..f.length]
62
+ f[(@configuration.destination_path.length + 1), f.length]
60
63
  end
61
64
  end
62
65
  end
@@ -0,0 +1,37 @@
1
+ require 'yaml'
2
+ require 'deep_merge'
3
+
4
+ module Usmu
5
+ class MetadataService
6
+ def initialize(folder)
7
+ @base = folder
8
+ end
9
+
10
+ def metadata(file)
11
+ last_folder = file.rindex('/')
12
+ base_meta = last_folder ? metadata(file[0..(last_folder - 1)]) : {}
13
+
14
+ metafile = if File.directory?(File.join(@base, file))
15
+ file + '/meta.yml'
16
+ else
17
+ dot_position = File.basename(file).rindex('.')
18
+ if (!dot_position.nil?) && dot_position > 0
19
+ file[0, file.rindex('.')] + '.meta.yml'
20
+ else
21
+ file + '.meta.yml'
22
+ end
23
+ end
24
+
25
+ metafile = File.join(@base, metafile)
26
+ if File.exist? metafile
27
+ base_meta.deep_merge! YAML.load_file(metafile)
28
+ else
29
+ base_meta
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ attr_reader :base
36
+ end
37
+ end
@@ -15,7 +15,7 @@ module Usmu
15
15
  # @!attribute [r] layouts
16
16
  # @return [Array<Usmu::Layout>] a list of layouts available in this website.
17
17
  def layouts
18
- @configuration.layouts_files.map {|l| Usmu::Template::Layout.new(@configuration, l) }
18
+ @configuration.layouts_files.map {|l| Usmu::Template::Layout.new(@configuration, l, @configuration.layouts_metadata.metadata(l)) }
19
19
  end
20
20
 
21
21
  # @!attribute [r] renderables
@@ -29,10 +29,11 @@ module Usmu
29
29
  # Usmu::Template::StaticFile and thus be renderable, however most files will be one of the subclasses of that class.
30
30
  def renderables
31
31
  @configuration.source_files.map do |filename|
32
- if Usmu::Template::Layout.is_valid_file? 'source', filename
33
- Usmu::Template::Page.new(@configuration, filename)
32
+ metadata = @configuration.source_metadata.metadata(filename)
33
+ if Usmu::Template::Layout.is_valid_file?('source', filename) && (!metadata['static'])
34
+ Usmu::Template::Page.new(@configuration, filename, metadata)
34
35
  else
35
- Usmu::Template::StaticFile.new(@configuration, filename)
36
+ Usmu::Template::StaticFile.new(@configuration, filename, metadata)
36
37
  end
37
38
  end
38
39
  end
@@ -34,7 +34,8 @@ module Usmu
34
34
  Dir["#{configuration.includes_path}/#{name}.*"].each do |f|
35
35
  filename = File.basename(f)
36
36
  if filename != "#{name}.meta.yml"
37
- return new(configuration, f[(configuration.includes_path.length + 1)..f.length])
37
+ path = f[(configuration.includes_path.length + 1)..f.length]
38
+ return new(configuration, path, configuration.includes_metadata.metadata(path))
38
39
  end
39
40
  end
40
41
  nil
@@ -16,11 +16,11 @@ module Usmu
16
16
 
17
17
  # @param configuration [Usmu::Configuration] The configuration for the website we're generating.
18
18
  # @param name [String] The name of the file in the source directory.
19
+ # @param metadata [Hash] The metadata for the file.
19
20
  # @param type [String] The type of template to use with the file. Used for testing purposes.
20
21
  # @param content [String] The content of the file. Used for testing purposes.
21
- # @param metadata [String] The metadata for the file. Used for testing purposes.
22
- def initialize(configuration, name, type = nil, content = nil, metadata = nil)
23
- super(configuration, name)
22
+ def initialize(configuration, name, metadata, type = nil, content = nil)
23
+ super(configuration, name, metadata, type, content)
24
24
 
25
25
  if type.nil?
26
26
  type = name.split('.').last
@@ -37,16 +37,6 @@ module Usmu
37
37
  end
38
38
  @content = content
39
39
 
40
- if metadata.nil?
41
- meta_file = "#{path}.meta.yml"
42
- metadata = if File.exist? meta_file
43
- YAML.load_file(meta_file)
44
- else
45
- {}
46
- end
47
- end
48
- @metadata = metadata
49
-
50
40
  @parent = Layout.find_layout(configuration, self.metadata['layout'])
51
41
 
52
42
  # Don't use the parent if it would result in weirdness
@@ -64,7 +54,7 @@ module Usmu
64
54
  # This will include any metadata from parent templates and default metadata
65
55
  def metadata
66
56
  if @parent.nil?
67
- (@configuration['default meta'] || {}).dup.deep_merge!(@metadata)
57
+ @configuration['default meta', default: {}].dup.deep_merge!(@metadata)
68
58
  else
69
59
  @parent.metadata.deep_merge!(@metadata)
70
60
  end
@@ -252,7 +242,8 @@ module Usmu
252
242
  Dir["#{layouts_path}/#{name}.*"].each do |f|
253
243
  filename = File.basename(f)
254
244
  if filename != "#{name}.meta.yml"
255
- return new(configuration, f[(layouts_path.length + 1)..f.length])
245
+ path = f[(layouts_path.length + 1)..f.length]
246
+ return new(configuration, path, configuration.layouts_metadata.metadata(path))
256
247
  end
257
248
  end
258
249
  else
@@ -7,11 +7,11 @@ module Usmu
7
7
 
8
8
  # @param configuration [Usmu::Configuration] The configuration for the website we're generating.
9
9
  # @param name [String] The name of the file in the source directory.
10
+ # @param metadata [Hash] The metadata for the file.
10
11
  # @param type [String] The type of template to use with the file. Used for testing purposes.
11
12
  # @param content [String] The content of the file. Used for testing purposes.
12
- # @param metadata [String] The metadata for the file. Used for testing purposes.
13
- def initialize(configuration, name, type = nil, content = nil, metadata = nil)
14
- super(configuration, name, type, content, metadata)
13
+ def initialize(configuration, name, metadata, type = nil, content = nil)
14
+ super(configuration, name, metadata, type, content)
15
15
 
16
16
  current_parent = parent
17
17
  until current_parent.nil?
@@ -11,16 +11,17 @@ module Usmu
11
11
 
12
12
  # @param configuration [Usmu::Configuration] The configuration for the website we're generating.
13
13
  # @param name [String] The name of the file in the source directory.
14
+ # @param metadata [Hash] The metadata for the file.
14
15
  # @param type [String] The type of template to use with the file. Not used for StaticFile.
15
16
  # Used for testing purposes.
16
17
  # @param content [String] The content of the file. Used for testing purposes.
17
- # @param metadata [String] The metadata for the file. Used for testing purposes.
18
- def initialize(configuration, name, type = nil, content = nil, metadata = nil)
18
+ def initialize(configuration, name, metadata, type = nil, content = nil)
19
19
  @log = Logging.logger[self]
20
20
  @log.debug("Creating <##{self.class.name} @name=\"#{name}\">")
21
21
 
22
22
  @configuration = configuration
23
23
  @name = name
24
+ @metadata = metadata
24
25
  @type = type
25
26
  @content = content
26
27
  end
@@ -20,6 +20,7 @@ module Usmu
20
20
  # @param [Array<String>] args Command line arguments, ie. ARGV.
21
21
  def initialize(args)
22
22
  @log = Logging.logger[self]
23
+ initialize_logging args
23
24
  @commander = initialize_commander(args)
24
25
 
25
26
  Usmu.plugins.load_plugins
@@ -49,6 +50,30 @@ module Usmu
49
50
 
50
51
  private
51
52
 
53
+ def initialize_logging(args)
54
+ i = 0
55
+ while i < args.length
56
+ case args[i]
57
+ when '-v', '--verbose'
58
+ args.delete_at i
59
+ Usmu.verbose_logging
60
+ when '-q', '--quiet'
61
+ args.delete_at i
62
+ Usmu.quiet_logging
63
+ when '--log'
64
+ if args.length > i + 1
65
+ args.delete_at i
66
+ path = args.delete_at i
67
+ Usmu.add_file_logger path
68
+ else
69
+ i += 1
70
+ end
71
+ else
72
+ i += 1
73
+ end
74
+ end
75
+ end
76
+
52
77
  # Helper function to setup a Commander runner
53
78
  # @return [Commander::Runner]
54
79
  def initialize_commander(args)
@@ -58,10 +83,11 @@ module Usmu
58
83
  commander.program :description, 'Static site generator powered by Tilt'
59
84
  commander.program :int_message, 'Interrupt received, closing...'
60
85
 
61
- commander.global_option('-v', '--verbose') { Usmu.verbose_logging }
62
- commander.global_option('-q', '--quiet') { Usmu.quiet_logging }
63
- commander.global_option('--log STRING', String) {|log| Usmu.add_file_logger(log) }
64
86
  commander.global_option('--config STRING', String, &method(:load_configuration))
87
+ # Logging options are manually processed in #initialize_logging, but included here for user documentations sake
88
+ commander.global_option('-v', '--verbose')
89
+ commander.global_option('-q', '--quiet')
90
+ commander.global_option('--log STRING', String)
65
91
 
66
92
  commander
67
93
  end