usmu 0.3.0 → 0.3.1

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: ed2e494db784cf3a3c1eb959eb36cd23460e9f4e
4
- data.tar.gz: 300f0c268563caa186ade7f41d84a12a2d72c4fe
3
+ metadata.gz: 8fc86dae15be6aceae0a11ed6b8d31b381eb2fda
4
+ data.tar.gz: e86a3100c2b95c4f095597c12b302eee60e61352
5
5
  SHA512:
6
- metadata.gz: e338182d6654d55cd1495d12702b3dbdac35a48fa9c79ebec0c846fb75bf01cbcbdbd230a2fa279c56eb01ccca9d0dd64e3aa92a996ec2d826debeb54e9b70ad
7
- data.tar.gz: b528d3ccb26688545f2c3ea277edfab575abe72d266be8fc361d8fb1a1762c360d30cc905a8842da20232a8b2ab85d530a898f67804f9b8517f3e81527a0ec97
6
+ metadata.gz: f198fb4e39bf471a56324c001216e2eee1041b9c04ec8f842d2c62c36dc0524f1e15598ae097aaf6af395b2ca8f249030f7748d1bd9636351f2c4d2afe86fade
7
+ data.tar.gz: bfee2b4b896e7d1dd990beb33eb0c76c9e80647f29e4cb6cbc9afee036a6aff166b7a1ce3f57e83d4c304a0086fec0c9cad2b294fd29fb9423ca776170be8279
data/.yardopts CHANGED
@@ -1 +1 @@
1
- --private --protected --hide-void-return -m markdown -M redcarpet lib/**/*.rb - README.md
1
+ --private --protected --default-return void -m markdown -M redcarpet -- lib/**/*.rb - README.md CHANGELOG.md
@@ -1,5 +1,15 @@
1
1
  # Usmu Change Log
2
2
 
3
+ ## 0.3.1
4
+
5
+ Matthew Scharley <matt.scharley@gmail.com>
6
+
7
+ * Add gemnasium badge (9449a8e605a3176a5e43d289cf7c0da9f38aa5ea)
8
+ * Add a bunch of documentation (c1eca0f79f7beecaf945237a425f8963846e83a3)
9
+ * Fix a few issues from cane (bae78ee394af4fc86d71d8754434a8c6f04100e7)
10
+ * Small fixups for the build scripts (d14b0b2822c704103896f7b462640709704f04b7)
11
+ * Allow Configuration to be indexed with a full path safely (110965b9058970ba82ee36bf4bc491e110996ad4)
12
+
3
13
  ## 0.3.0
4
14
 
5
15
  Matthew Scharley <matt.scharley@gmail.com>
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # usmu [![Build Status](https://travis-ci.org/usmu/usmu.svg?branch=master)](https://travis-ci.org/usmu/usmu)
1
+ # usmu [![Build Status](https://travis-ci.org/usmu/usmu.svg?branch=master)](https://travis-ci.org/usmu/usmu) [![Dependency Status](https://gemnasium.com/usmu/usmu.svg)](https://gemnasium.com/usmu/usmu)
2
2
 
3
3
  **Source:** [https://github.com/usmu/usmu](https://github.com/usmu/usmu)
4
4
  **Author:** Matthew Scharley
@@ -64,6 +64,7 @@ module Usmu
64
64
  end
65
65
  # :nocov:
66
66
 
67
+ # @return [Usmu::Plugin] a handler to the plugin interface
67
68
  def self.plugins
68
69
  @plugins ||= Usmu::Plugin.new
69
70
  end
@@ -76,11 +76,33 @@ module Usmu
76
76
  # working directory to the configuration file and other factors. The accessor functions such as `#source_path`
77
77
  # should be preferred for most usages.
78
78
  #
79
- # @param [String, Symbol] index The index to return.
80
- # @return [Array, Hash, String, Symbol] Returns a value from the hash loaded from YAML. The type of value will
81
- # ultimately depend on the configuration file and the index provided.
82
- def [](index)
83
- @config[index]
79
+ # @param [String, Symbol] indices
80
+ # A list of indices to use to find the value to return. Can also include an options hash with the
81
+ # following options:
82
+ #
83
+ # * `:default`: Sets the default value if the value can't be found.
84
+ #
85
+ # @return [Array, Hash, String, Symbol]
86
+ # Returns a value from the hash loaded from YAML. The type of value will ultimately depend on the configuration
87
+ # file and the indices provided.
88
+ def [](*indices)
89
+ if indices[-1].class.name == 'Hash'
90
+ opts = indices.pop
91
+ else
92
+ opts = {}
93
+ end
94
+
95
+ value = @config
96
+ while indices.length > 0
97
+ i = indices.shift
98
+ if value.key? i
99
+ value = value[i]
100
+ else
101
+ return opts[:default]
102
+ end
103
+ end
104
+
105
+ value
84
106
  end
85
107
 
86
108
  private
@@ -123,7 +145,6 @@ module Usmu
123
145
  # Helper function to search a directory recursively and return a list of files that are renderable.
124
146
  #
125
147
  # @param [String] directory the directory to search
126
- # @param [Boolean] layout is this directory a layouts_path
127
148
  # @return [Array<Usmu::Layout>, Array<Usmu::StaticFile>] Either an array of Layouts or StaticFiles in the directory
128
149
  def get_files(directory)
129
150
  Dir["#{directory}/**/{*,.??*}"].
@@ -1,6 +1,9 @@
1
1
 
2
2
  module Usmu
3
+ # Singletonish class to load plugins and act as an interface to them. Shouldn't be created directly.
4
+ # @see Usmu.plugins
3
5
  class Plugin
6
+ # Constructor for the plugin interface.
4
7
  def initialize
5
8
  @log = Logging.logger['Usmu::Plugin']
6
9
  end
@@ -9,24 +12,12 @@ module Usmu
9
12
  # with the string 'usmu-' will be recognised as a plugin. This will load the gem according to the RubyGems
10
13
  # recommendations for naming schemes. A gem named `usmu-s3_uploader` will be loaded by requiring the path
11
14
  # `'usmu/s3_uploader'` and then then the class `Usmu::S3Uploader` will be instantiated as the plugins interface.
12
- #
13
- # @return [void]
14
15
  def load_plugins
15
- loaded = []
16
+ @loaded = []
16
17
  @log.debug('Loading plugins')
17
18
  @log.debug('Loaded Usmu::Plugin::Core')
18
19
  plugins.push Usmu::Plugin::Core.new
19
- Gem::Specification.find_all { |s| s.name =~ /^usmu-/ }.each do |spec|
20
- load_path = spec.name.gsub('-', '/')
21
- require load_path
22
-
23
- unless loaded.include? load_path
24
- loaded << load_path
25
- klass = load_path.split('/').map {|s| s.split('_').map(&:capitalize).join }.join('::')
26
- @log.debug("Loading plugin #{klass} from '#{load_path}'")
27
- plugins.push plugin_get(klass)
28
- end
29
- end
20
+ Gem::Specification.find_all { |s| s.name =~ /^usmu-/ }.each &method(:load_gem)
30
21
  @log.debug("Loaded: #{plugins.inspect}")
31
22
  end
32
23
 
@@ -38,9 +29,11 @@ module Usmu
38
29
 
39
30
  # Call all plugins and collate any data returned. nil can be returned explicitly to say this plugin has nothing to
40
31
  # return.
32
+ #
41
33
  # @param [Symbol] method The name of the method to call. This should be namespaced somehow. For example, a plugin
42
34
  # called `usmu-s3` could use the method namespace `s3` and have a hook called `:s3_upload`
43
35
  # @param [Array] args The arguments to pass through to plugins. Can be empty.
36
+ # @return [Array] An array of non-nil values returned from plugins
44
37
  def invoke(method, *args)
45
38
  @log.debug("Invoking plugin API #{method}")
46
39
  plugins.map do |p|
@@ -55,11 +48,31 @@ module Usmu
55
48
 
56
49
  private
57
50
 
51
+ # Helper function to load and instantiate plugin classes
52
+ #
53
+ # @param [String] klass The name of the class to load
54
+ # @return [Object] A plugin object
58
55
  def plugin_get(klass)
59
56
  object.const_get(klass).new
60
57
  rescue NameError
61
58
  # Ruby 1.9.3, dowp
62
59
  klass.split('::').reduce(Object) {|memo, o| memo.const_get o }.new
63
60
  end
61
+
62
+ # Helper function to load a plugin from a gem specification
63
+ #
64
+ # @param [Gem::Specification] spec
65
+ def load_gem(spec)
66
+ load_path = spec.name.gsub('-', '/')
67
+ require load_path
68
+
69
+ unless @loaded.include? load_path
70
+ @loaded << load_path
71
+ klass = load_path.split('/').map {|s| s.split('_').map(&:capitalize).join }.join('::')
72
+ @log.debug("Loading plugin #{klass} from '#{load_path}'")
73
+ plugins.push plugin_get(klass)
74
+ end
75
+ nil
76
+ end
64
77
  end
65
78
  end
@@ -2,11 +2,18 @@ require 'fileutils'
2
2
 
3
3
  module Usmu
4
4
  class Plugin
5
+ # Usmu Core's plugin. We dog-food several plugin integration points.
5
6
  class Core
7
+ # Basic constructor.
6
8
  def initialize
7
9
  @log = Logging.logger[self]
8
10
  end
9
11
 
12
+ # We add two commands: `generate` and `init [path]`.
13
+ #
14
+ # @see #command_generate
15
+ # @see #command_init
16
+ # @see Usmu::Plugin::CoreHooks#commands
10
17
  def commands(ui, c)
11
18
  @log.debug('Adding core console commands...')
12
19
  @ui = ui
@@ -23,12 +30,19 @@ module Usmu
23
30
  end
24
31
  end
25
32
 
26
- # @return [void]
33
+ # Command to generate a website.
34
+ #
35
+ # @param [Array<String>] args arguments passed by the user.
36
+ # @param [Hash] options options parsed by Commander
27
37
  def command_generate(args, options)
28
38
  @site_generator = Usmu::SiteGenerator.new(@ui.configuration)
29
39
  @site_generator.generate
30
40
  end
31
41
 
42
+ # Command to initialise a new website.
43
+ #
44
+ # @param [Array<String>] args arguments passed by the user.
45
+ # @param [Hash] options options parsed by Commander
32
46
  def command_init(args, options)
33
47
  @log.info("Usmu v#{Usmu::VERSION}")
34
48
  @log.info('')
@@ -42,14 +56,23 @@ module Usmu
42
56
  from = File.realpath(File.join(File.dirname(__FILE__), '../../../share/init-site'))
43
57
 
44
58
  @log.info("Copying #{from} -> #{path}")
45
- Dir["#{from}/**/{*,.??*}"].each do |file|
46
- output_name = file[(from.length + 1)..file.length]
47
- @log.success "Creating #{output_name}..."
48
- unless File.directory? file
49
- output_path = "#{path}/#{output_name}"
50
- FileUtils.mkdir_p File.dirname(output_path) unless File.directory? File.dirname(output_path)
51
- FileUtils.copy(file, output_path)
52
- end
59
+ Dir["#{from}/**/{*,.??*}"].each {|f| init_copy_file(from, path, f) }
60
+ end
61
+
62
+ private
63
+
64
+ # Helper to copy a file.
65
+ #
66
+ # @param [String] from
67
+ # @param [String] to
68
+ # @param [String] file
69
+ def init_copy_file(from, to, file)
70
+ output_name = file[(from.length + 1)..file.length]
71
+ @log.success "Creating #{output_name}..."
72
+ unless File.directory? file
73
+ output_path = "#{to}/#{output_name}"
74
+ FileUtils.mkdir_p File.dirname(output_path) unless File.directory? File.dirname(output_path)
75
+ FileUtils.copy(file, output_path)
53
76
  end
54
77
  end
55
78
  end
@@ -0,0 +1,14 @@
1
+
2
+ module Usmu
3
+ class Plugin
4
+ # This class describes all the hooks available from Usmu Core.
5
+ # @api hooks
6
+ class CoreHooks
7
+ # Hook to allow adding commands to the console UI.
8
+ #
9
+ # @param [Usmu::Ui::Console] ui The UI instance for this session.
10
+ # @param [Commander::Runner] c The Commander instance to add commands to.
11
+ def commands(ui, c); end
12
+ end
13
+ end
14
+ end
@@ -58,20 +58,28 @@ module Usmu
58
58
  @log.info("Destination: #{@configuration.destination_path}")
59
59
  @log.info('')
60
60
 
61
- renderables.each do |page|
62
- @log.success("creating #{page.output_filename}...")
63
- @log.debug("Rendering #{page.output_filename} from #{page.name}")
64
- file = File.join(@configuration.destination_path, page.output_filename)
65
- directory = File.dirname(file)
61
+ renderables.each &method(:generate_page)
62
+ nil
63
+ end
66
64
 
67
- unless File.directory?(directory)
68
- FileUtils.mkdir_p(directory)
69
- end
65
+ private
70
66
 
71
- File.write file, page.render
72
- FileUtils.touch file, :mtime => File.stat(page.input_path).mtime
67
+ # Helper function to generate a page
68
+ #
69
+ # @param [Usmu::Template::Page] page
70
+ def generate_page(page)
71
+ output_filename = page.output_filename
72
+ @log.success("creating #{output_filename}...")
73
+ @log.debug("Rendering #{output_filename} from #{page.name}")
74
+ file = File.join(@configuration.destination_path, output_filename)
75
+ directory = File.dirname(file)
76
+
77
+ unless File.directory?(directory)
78
+ FileUtils.mkdir_p(directory)
73
79
  end
74
- nil
80
+
81
+ File.write file, page.render
82
+ FileUtils.touch file, :mtime => File.stat(page.input_path).mtime
75
83
  end
76
84
  end
77
85
  end
@@ -1,14 +1,26 @@
1
- # We really should include this, but it causes an include loop and Include has a strict dependency on Layout due to
2
- # the inheritance structure. Oh well. Perhaps I'll think of something later.
3
- #require 'usmu/template/include'
4
1
 
5
2
  module Usmu
3
+ # This module is a namespace for all the different types of templates in use by Usmu. It has no functionality
4
+ # attached to it directly.
6
5
  module Template
6
+ # Helper functions that get imported into the local scope of templates
7
7
  class Helpers
8
+ # Create a new Helpers instance. These are created on demand as needed by templates, there is not a singleton
9
+ # instance.
8
10
  def initialize(configuration)
9
11
  @configuration = configuration
10
12
  end
11
13
 
14
+ # Finds and renders a named include.
15
+ #
16
+ # @param [String] name
17
+ # The name of the include file. Should not include file extension.
18
+ # @param [Hash] args
19
+ # The named arguments to provide to the include file. These are incorporated as additional
20
+ # metadata available to the include file.
21
+ # @return [String] The rendered file.
22
+ #
23
+ # @api template_helpers
12
24
  def include(name, args = {})
13
25
  inc = Usmu::Template::Include.find_include(@configuration, name)
14
26
  inc.arguments = args
@@ -7,6 +7,8 @@ module Usmu
7
7
 
8
8
  private
9
9
 
10
+ # Preserved version of the layout metadata logic
11
+ # @see Usmu::Template::Layout#metadata
10
12
  alias :layout_metadata :metadata
11
13
 
12
14
  public
@@ -79,7 +81,7 @@ module Usmu
79
81
  arguments.each do |i, value|
80
82
  args[i.class.name == 'String' ? i : i.to_s] = value
81
83
  end
82
-
84
+
83
85
  {'site' => @configuration}.deep_merge!(metadata).deep_merge!(args).deep_merge!(variables)
84
86
  end
85
87
  end
@@ -142,7 +142,10 @@ module Usmu
142
142
  @layout_history = @layout_history || {}
143
143
  @layout_history[configuration] = @layout_history[configuration] || {}
144
144
  if @layout_history[configuration][name]
145
- Logging.logger[self].debug("Layout loop detected. Current loaded layouts: #{@layout_history[configuration].inspect}")
145
+ Logging.logger[self].debug(
146
+ 'Layout loop detected. Current loaded layouts: ' +
147
+ @layout_history[configuration].inspect
148
+ )
146
149
  return nil
147
150
  else
148
151
  Logging.logger[self].debug("Loading layout '#{name}'")
@@ -17,18 +17,10 @@ module Usmu
17
17
  @configuration || load_configuration('usmu.yml')
18
18
  end
19
19
 
20
+ # @param [Array<String>] args Command line arguments, ie. ARGV.
20
21
  def initialize(args)
21
22
  @log = Logging.logger[self]
22
- @commander = Commander::Runner.new args
23
-
24
- @commander.program :version, Usmu::VERSION
25
- @commander.program :description, 'Static site generator powered by Tilt'
26
- @commander.program :int_message, 'Interrupt received, closing...'
27
-
28
- @commander.global_option('-v', '--verbose') { Usmu.verbose_logging }
29
- @commander.global_option('-q', '--quiet') { Usmu.quiet_logging }
30
- @commander.global_option('--log STRING', String) {|log| Usmu.add_file_logger(log) }
31
- @commander.global_option('--config STRING', String, &method(:load_configuration))
23
+ @commander = initialize_commander(args)
32
24
 
33
25
  Usmu.plugins.load_plugins
34
26
  Usmu.plugins.invoke :commands, self, @commander
@@ -54,6 +46,25 @@ module Usmu
54
46
  end
55
47
  @configuration
56
48
  end
49
+
50
+ private
51
+
52
+ # Helper function to setup a Commander runner
53
+ # @return [Commander::Runner]
54
+ def initialize_commander(args)
55
+ commander = Commander::Runner.new args
56
+
57
+ commander.program :version, Usmu::VERSION
58
+ commander.program :description, 'Static site generator powered by Tilt'
59
+ commander.program :int_message, 'Interrupt received, closing...'
60
+
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
+ commander.global_option('--config STRING', String, &method(:load_configuration))
65
+
66
+ commander
67
+ end
57
68
  end
58
69
  end
59
70
  end
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Usmu
3
3
  # The current version string for the gem
4
- VERSION = '0.3.0'
4
+ VERSION = '0.3.1'
5
5
  end
@@ -158,4 +158,19 @@ RSpec.describe Usmu::Configuration do
158
158
  expect(@configuration.source_files).to eq(%w(index.md test/foo.md))
159
159
  end
160
160
  end
161
+
162
+ it 'should allow indexing the configuration file' do
163
+ configuration = Usmu::Configuration.from_hash({test: 'foo'})
164
+ expect(configuration[:test]).to eq('foo')
165
+ end
166
+
167
+ it 'should allow indexing the configuration file with a default value' do
168
+ configuration = Usmu::Configuration.from_hash({test: 'foo'})
169
+ expect(configuration[:bar, default: 'baz']).to eq('baz')
170
+ end
171
+
172
+ it 'should allow indexing the configuration file using a path of indices' do
173
+ configuration = Usmu::Configuration.from_hash({test: {bar: 'foo'}})
174
+ expect(configuration[:test, :bar]).to eq('foo')
175
+ end
161
176
  end
@@ -38,4 +38,5 @@ Gem::Specification.new do |spec|
38
38
  spec.add_development_dependency 'guard', '~> 2.8'
39
39
  spec.add_development_dependency 'guard-rspec', '~> 4.3'
40
40
  spec.add_development_dependency 'turnip', '~> 1.2'
41
+ spec.add_development_dependency 'sass', '~> 3.4'
41
42
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: usmu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Scharley
@@ -279,11 +279,11 @@ files:
279
279
  - README.md
280
280
  - Rakefile
281
281
  - bin/usmu
282
- - cucumber.yml
283
282
  - lib/usmu.rb
284
283
  - lib/usmu/configuration.rb
285
284
  - lib/usmu/plugin.rb
286
285
  - lib/usmu/plugin/core.rb
286
+ - lib/usmu/plugin/core_hooks.rb
287
287
  - lib/usmu/site_generator.rb
288
288
  - lib/usmu/template/helpers.rb
289
289
  - lib/usmu/template/include.rb
@@ -1,2 +0,0 @@
1
- ---
2
- default: test/features --format pretty