lib/brief/briefcase.rb in brief-1.9.4 vs lib/brief/briefcase.rb in brief-1.9.6
- old
+ new
@@ -11,11 +11,11 @@
load_configuration
use(:app, options[:app]) if options[:app]
load_model_definitions
- if Brief.case.nil?
+ if Brief.case(false).nil?
Brief.case = self
end
Brief.cases[root.basename.to_s] ||= self
end
@@ -57,20 +57,24 @@
name: briefcase.folder_name.to_s.titlecase,
settings: settings,
cache_key: briefcase.cache_key
}
+ if params[:include_data] || params[:data]
+ base[:data] = data.as_json
+ end
+
if params[:include_schema] || params[:schema]
base[:schema] = schema_map
end
if params[:include_models] || params[:models]
model_settings = {
docs_path: docs_path
}
- %w(urls content rendered).each do |opt|
+ %w(urls content rendered attachments).each do |opt|
model_settings[opt.to_sym] = !!(params[opt.to_sym] || params["include_#{opt}".to_sym])
end
all = all_models.compact
@@ -133,11 +137,11 @@
run(config_path) if config_path.exist?
end
def run(code_or_file)
code = code_or_file.is_a?(Pathname) ? code_or_file.read : code
- instance_eval(code)
+ instance_eval(code) rescue nil
end
def uses_app?
options.key?(:app) && Brief::Apps.available?(options[:app].to_s)
end
@@ -193,15 +197,45 @@
def root
Pathname(options.fetch(:root) { Brief.pwd })
end
+ def find_asset(needle)
+ found = assets_trail.find(needle)
+ found && Pathname(found)
+ end
+
+ def assets_path
+ root.join options.fetch(:assets_path) { config.assets_path }
+ end
+
+ def assets_trail
+ @assets_trail ||= Hike::Trail.new(assets_path).tap do |trail|
+ trail.append_extensions '.svg', '.png', '.pdf', '.jpg', '.gif', '.mov'
+ assets_path.children.select(&:directory?).each {|dir| trail.prepend_path(assets_path); trail.append_path(assets_path.join(dir)) }
+ end
+ end
+
+ def docs_trail
+ @docs_trail ||= Hike::Trail.new(docs_path).tap do |trail|
+ trail.append_extensions '.md', '.html.md', '.markdown'
+ docs_path.children.select(&:directory?).each {|dir| trail.prepend_path(docs_path); trail.append_path(docs_path.join(dir)) }
+ end
+ end
+
def docs_path
root.join options.fetch(:docs_path) { config.docs_path }
end
def data_path
root.join options.fetch(:data_path) { config.data_path }
+ end
+
+ def data_trail
+ @docs_trail ||= Hike::Trail.new(data_path).tap do |trail|
+ trail.append_extensions '.yaml', '.js', '.json', '.xls', '.xlsx', '.csv', '.txt'
+ trail.append_path(data_path)
+ end
end
def models_path
value = options.fetch(:models_path) { config.models_path }