Commit 56e6930e by Jon Frisby

Merge remote-tracking branch 'appsinyourpants/restart' into development

Conflicts: lib/annotate/annotate_models.rb
parents bb88aa6c 2293d1e0
......@@ -28,7 +28,9 @@
* Accept String or Symbol for :position (et al) options.
* Rename "annotate" bin to "annotate_models" to avoid conflicting with
ImageMagick.
* Add rdoc output formatting as an option.
* Add RDoc output formatting as an option.
* Add Markdown output formatting as an option.
* Add option to force annotation regeneration.
* Add new configuration option for controlling where info is placed in
fixtures/factories.
* Fix for models without tables.
......
......@@ -73,8 +73,12 @@ OptionParser.new do |opts|
exclusions.each { |exclusion| ENV["exclude_#{exclusion}"] = "yes" }
end
opts.on('-f', '--format [bare|rdoc]', ['bare', 'rdoc'], 'rdoc: render Schema Infomation as RDoc') do |fmt|
ENV['format_#{fmt}'] = 'yes'
opts.on('-f', '--format [bare|rdoc|markdown]', ['bare', 'rdoc', 'markdown'], 'rdoc: render Schema Infomation as RDoc') do |fmt|
ENV["format_#{fmt}"] = 'yes'
end
opts.on('--force', 'Force new annotations even if there are no changes.') do |force|
ENV['force'] = 'yes'
end
end.parse!
......
module AnnotateModels
# Annotate Models plugin use this header
COMPAT_PREFIX = "== Schema Info"
PREFIX = "== Schema Information"
END_MARK = "== Schema Information End"
PATTERN = /\n?# #{COMPAT_PREFIX}.*?\n(#.*\n)*\n*/
COMPAT_PREFIX = "== Schema Info"
COMPAT_PREFIX_MD = "## Schema Info"
PREFIX = "== Schema Information"
PREFIX_MD = "## Schema Information"
END_MARK = "== Schema Information End"
PATTERN = /^\n?# (?:#{COMPAT_PREFIX}|#{COMPAT_PREFIX_MD}).*?\n(#.*\n)*\n/
# File.join for windows reverse bar compat?
# I dont use windows, can`t test
UNIT_TEST_DIR = File.join("test", "unit" )
......@@ -62,6 +65,12 @@ module AnnotateModels
max_size = klass.column_names.map{|name| name.size}.max || 0
max_size += options[:format_rdoc] ? 5 : 1
if(options[:format_markdown])
info<< sprintf( "# %-#{max_size + 4}.#{max_size + 4}s | %-17.17s | %s \n", 'Field', 'Type', 'Attributes' )
info<< "# #{ '-' * ( max_size + 4 ) } | #{'-' * 17} | #{ '-' * 25 } \n"
end
cols = klass.columns
cols = cols.sort_by(&:name) unless(options[:no_sort])
cols.each do |col|
......@@ -99,6 +108,8 @@ module AnnotateModels
if options[:format_rdoc]
info << sprintf("# %-#{max_size}.#{max_size}s<tt>%s</tt>", "*#{col.name}*::", attrs.unshift(col_type).join(", ")).rstrip + "\n"
elsif options[:format_markdown]
info << sprintf("# **%-#{max_size}.#{max_size}s** | `%-16.16s` | `%s `", col.name, col_type, attrs.join(", ")).rstrip + "\n"
else
info << sprintf("# %-#{max_size}.#{max_size}s:%-16.16s %s", col.name, col_type, attrs.join(", ")).rstrip + "\n"
end
......@@ -162,7 +173,7 @@ module AnnotateModels
encoding = Regexp.new(/(^#\s*encoding:.*\n)|(^# coding:.*\n)|(^# -\*- coding:.*\n)/)
encoding_header = old_content.match(encoding).to_s
if old_columns == new_columns
if old_columns == new_columns && !options[:force]
false
else
# Strip the old schema info, and insert new schema info.
......@@ -304,7 +315,7 @@ module AnnotateModels
end
end
header = PREFIX.dup
header = options[:format_markdown] ? PREFIX_MD.dup : PREFIX.dup
if options[:include_version]
version = ActiveRecord::Migrator.current_version rescue 0
......
......@@ -14,5 +14,7 @@ if(Rails.env.development?)
ENV['ignore_model_sub_dir'] = "false"
ENV['skip_on_db_migrate'] = "false"
ENV['format_rdoc'] = "false"
ENV['format_markdown'] = "false"
ENV['no_sort'] = "false"
ENV['force'] = "false"
end
......@@ -18,7 +18,9 @@ task :annotate_models => :environment do
options[:exclude_fixtures] = ENV['exclude_fixtures'] =~ true_re
options[:ignore_model_sub_dir] = ENV['ignore_model_sub_dir'] =~ true_re
options[:format_rdoc] = ENV['format_rdoc'] =~ true_re
options[:format_markdown] = ENV['format_markdown'] =~ true_re
options[:no_sort] = ENV['no_sort'] =~ true_re
options[:force] = ENV['force'] =~ true_re
AnnotateModels.do_annotations(options)
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment