lib/palimpsest/environment.rb in palimpsest-0.1.1 vs lib/palimpsest/environment.rb in palimpsest-0.2.0
- old
+ new
@@ -30,13 +30,20 @@
# # server or local path that repos are under
# :server: "https://github.com/razor-x"
#
# # list of external repos
# :repos:
- # #- [ name, install_path, branch, server (optional) ]
- # - [ my_app, apps/my_app, master ]
- # - [ sub_app, apps/my_app/sub_app, my_feature, "https://bitbucket.org/razorx" ]
+ # #- [ name, install_path, branch, server (optional) ]
+ # - [ my_app, apps/my_app, master ]
+ # - [ sub_app, apps/my_app/sub_app, my_feature, "https://bitbucket.org/razorx" ]
+ #
+ # # list of excludes
+ # # matching paths are removed with {#remove_excludes}.
+ # :excludes:
+ # - _assets
+ # - apps/*/.gitignore
+ #
# # asset settings
# :assets:
# # all options are passed to Assets#options
# # options will use defaults set in Palimpsest::Asset::DEFAULT_OPTIONS if unset here
# # unless otherwise mentioned, options can be set or overridden per asset type
@@ -83,11 +90,11 @@
# # images can be part of the asset pipeline
# :images:
# :options:
# # requires the sprockets-image_compressor gem
# :image_compression: true
- # # options can be overridden per type
+ # # options can be overridden per type
# :output: images
# :paths:
# - assets/images
# ````
class Environment
@@ -163,10 +170,11 @@
# Removes the environment's working directory.
# @return [Environment] the current environment instance
def cleanup
FileUtils.remove_entry_secure directory if @directory
+ @config = nil
@directory = nil
@assets = []
@components = []
@populated = false
self
@@ -188,22 +196,27 @@
when :repo
fail RuntimeError, "Cannot populate without 'treeish'" if treeish.empty?
Utility.extract_repo site.repo, treeish, directory
@populated = true
when :source
- FileUtils.cp_r Dir["#{site.source}/*"], directory, preserve: true
+ Kernel.system 'rsync', '-rt', %q{--exclude='.git/'}, "#{site.source}/", directory
@populated = true
end
self
end
+ # @param settings [Hash] merged with current config
# @return [Hash] configuration loaded from {#options}`[:config_file]` under {#directory}
- def config
- populate unless populated
- @config = YAML.load_file "#{directory}/#{options[:config_file]}"
- validate_config if @config
+ def config settings = {}
+ if @config.nil?
+ populate unless populated
+ @config = YAML.load_file "#{directory}/#{options[:config_file]}"
+ validate_config if @config
+ end
+
+ @config.merge! settings
end
# @return [Array<Component>] components with paths loaded from config
def components
return @components if @components
@@ -250,10 +263,18 @@
def install_externals
externals.each { |e| e.install.cleanup }
self
end
+ # Remove all excludes defined by `config[:excludes]`.
+ # @return [Environment] the current environment instance
+ def remove_excludes
+ return self if config[:excludes].nil?
+ config[:excludes].map{ |e| Dir["#{directory}/#{e}"] }.flatten.each { |e| FileUtils.remove_entry_secure e }
+ self
+ end
+
# @return [Array<Assets>] assets with settings and paths loaded from config
def assets
return @assets if @assets
@assets = []
@@ -317,10 +338,14 @@
fail RuntimeError, 'bad option in config' if k == :sprockets_options
fail RuntimeError, message if k == :output && ! Utility.safe_path?(v)
end
end
+ @config[:excludes].each do |v|
+ fail RuntimeError, message unless Utility.safe_path? v
+ end unless @config[:excludes].nil?
+
@config[:external].each do |k, v|
next if k == :server
v.each do |repo|
fail RuntimeError, message unless Utility.safe_path? repo[1]
@@ -367,10 +392,10 @@
end unless asset_value.nil?
# process each asset path
asset_value.each_with_index do |path, i|
fail RuntimeError, message unless Utility.safe_path? path
- end
+ end if asset_key == :paths
end
end unless @config[:assets].nil?
@config
end