coherent 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. data/LICENSE +7 -1
  2. data/VERSION +1 -1
  3. data/app_generators/coherent/templates/distil.yml.erb +1 -1
  4. data/app_generators/coherent/templates/src/css/@name@.css.erb +26 -26
  5. data/bin/coherent +4 -0
  6. data/coherent.gemspec +20 -16
  7. data/demo_generators/gallery/templates/distil.yml.erb +1 -1
  8. data/demo_generators/gallery/templates/src/css/@name@.css.erb +26 -26
  9. data/lib/distilery.rb +1 -1
  10. data/lib/distilery/bundle-task.rb +37 -0
  11. data/lib/distilery/coherent-asset-filter.rb +2 -2
  12. data/lib/distilery/nib-file.rb +1 -1
  13. data/lib/plugin.rb +83 -0
  14. data/lib/plugin/commands.rb +12 -0
  15. data/lib/plugin/commands/discover.rb +78 -0
  16. data/lib/plugin/commands/info.rb +29 -0
  17. data/lib/plugin/commands/install.rb +76 -0
  18. data/lib/plugin/commands/list.rb +55 -0
  19. data/lib/plugin/commands/plugin.rb +105 -0
  20. data/lib/plugin/commands/remove.rb +29 -0
  21. data/lib/plugin/commands/source.rb +34 -0
  22. data/lib/plugin/commands/sources.rb +33 -0
  23. data/lib/plugin/commands/unsource.rb +36 -0
  24. data/lib/plugin/commands/update.rb +42 -0
  25. data/lib/plugin/environment.rb +97 -0
  26. data/lib/plugin/plugin.rb +160 -0
  27. data/lib/plugin/recursive-http-fetcher.rb +71 -0
  28. data/lib/plugin/repositories.rb +92 -0
  29. data/lib/plugin/repository.rb +36 -0
  30. metadata +20 -16
  31. data/generators/gallery_sample/USAGE +0 -5
  32. data/generators/gallery_sample/gallery_sample_generator.rb +0 -48
  33. data/generators/gallery_sample/templates/src/nibs/@name@/@name@.css +0 -116
  34. data/generators/gallery_sample/templates/src/nibs/@name@/@name@.html +0 -6
  35. data/generators/gallery_sample/templates/src/nibs/@name@/@name@.jsnib.erb +0 -40
  36. data/generators/gallery_sample/templates/src/nibs/@name@/@name@.json +0 -25
  37. data/generators/gallery_sample/templates/src/nibs/@name@/images/next.gif +0 -0
  38. data/generators/gallery_sample/templates/src/nibs/@name@/images/prev.gif +0 -0
  39. data/generators/gallery_sample/templates/src/nibs/@name@/photos/molly-1.jpg +0 -0
  40. data/generators/gallery_sample/templates/src/nibs/@name@/photos/molly-2.jpg +0 -0
  41. data/generators/gallery_sample/templates/src/nibs/@name@/photos/molly-3.jpg +0 -0
  42. data/generators/gallery_sample/templates/src/nibs/@name@/photos/molly-4.jpg +0 -0
  43. data/generators/gallery_sample/templates/src/nibs/@name@/photos/molly-5.jpg +0 -0
  44. data/lib/distilery/nib-task.rb +0 -83
@@ -23,7 +23,7 @@ class CoherentAssetFilter < FileReferenceFilter
23
23
  import_file= File.expand_path(File.join(file.parent_folder, $1))
24
24
 
25
25
  if (!File.exists?(import_file))
26
- file.error "Missing import file: #{$1}", line_num
26
+ file.warning "Missing asset: #{$1}", line_num
27
27
  "NIB.asset('#{$1}')"
28
28
  else
29
29
  asset= SourceFile.from_path(import_file)
@@ -42,7 +42,7 @@ class CoherentAssetFilter < FileReferenceFilter
42
42
  import_file= File.expand_path(File.join(file.parent_folder, $1))
43
43
 
44
44
  if (!File.exists?(import_file))
45
- file.error "Missing import file: #{$1}", line_num
45
+ file.warning "Missing import file: #{$1}", line_num
46
46
  "INC('#{$1}')"
47
47
  else
48
48
  asset= SourceFile.from_path(import_file)
@@ -10,4 +10,4 @@ class NibFile < JavascriptFile
10
10
  "js"
11
11
  end
12
12
 
13
- end
13
+ end
data/lib/plugin.rb ADDED
@@ -0,0 +1,83 @@
1
+ # This is the coherent plugin manager and was adapted from the Rails plugin
2
+ # manager by Ryan Tomayko (rtomayko@gmail.com).
3
+ #
4
+ # Listing available plugins:
5
+ #
6
+ # $ ./script/plugin list
7
+ # continuous_builder http://dev.rubyonrails.com/svn/rails/plugins/continuous_builder
8
+ # asset_timestamping http://svn.aviditybytes.com/rails/plugins/asset_timestamping
9
+ # enumerations_mixin http://svn.protocool.com/rails/plugins/enumerations_mixin/trunk
10
+ # calculations http://techno-weenie.net/svn/projects/calculations/
11
+ # ...
12
+ #
13
+ # Installing plugins:
14
+ #
15
+ # $ ./script/plugin install continuous_builder asset_timestamping
16
+ #
17
+ # Finding Repositories:
18
+ #
19
+ # $ ./script/plugin discover
20
+ #
21
+ # Adding Repositories:
22
+ #
23
+ # $ ./script/plugin source http://svn.protocool.com/rails/plugins/
24
+ #
25
+ # How it works:
26
+ #
27
+ # * Maintains a list of subversion repositories that are assumed to have
28
+ # a plugin directory structure. Manage them with the (source, unsource,
29
+ # and sources commands)
30
+ #
31
+ # * The discover command scrapes the following page for things that
32
+ # look like subversion repositories with plugins:
33
+ # http://wiki.rubyonrails.org/rails/pages/Plugins
34
+ #
35
+ # * Unless you specify that you want to use svn, script/plugin uses plain old
36
+ # HTTP for downloads. The following bullets are true if you specify
37
+ # that you want to use svn.
38
+ #
39
+ # * If `vendor/plugins` is under subversion control, the script will
40
+ # modify the svn:externals property and perform an update. You can
41
+ # use normal subversion commands to keep the plugins up to date.
42
+ #
43
+ # * Or, if `vendor/plugins` is not under subversion control, the
44
+ # plugin is pulled via `svn checkout` or `svn export` but looks
45
+ # exactly the same.
46
+ #
47
+ # Specifying revisions:
48
+ #
49
+ # * Subversion revision is a single integer.
50
+ #
51
+ # * Git revision format:
52
+ # - full - 'refs/tags/1.8.0' or 'refs/heads/experimental'
53
+ # - short: 'experimental' (equivalent to 'refs/heads/experimental')
54
+ # 'tag 1.8.0' (equivalent to 'refs/tags/1.8.0')
55
+ #
56
+ #
57
+ # This is Free Software, copyright 2005 by Ryan Tomayko (rtomayko@gmail.com)
58
+ # and is licensed MIT: (http://www.opensource.org/licenses/mit-license.php)
59
+
60
+
61
+
62
+
63
+ require 'open-uri'
64
+ require 'fileutils'
65
+ require 'tempfile'
66
+
67
+ include FileUtils
68
+
69
+ LIB_DIR = File.dirname(__FILE__)
70
+ $:.unshift(LIB_DIR)
71
+
72
+ $verbose = false
73
+
74
+ require 'plugin/commands'
75
+ require 'plugin/environment'
76
+ require 'plugin/plugin'
77
+ require 'plugin/recursive-http-fetcher'
78
+ require 'plugin/repositories'
79
+ require 'plugin/repository'
80
+
81
+ require 'plugin/commands'
82
+
83
+
@@ -0,0 +1,12 @@
1
+ require 'optparse'
2
+
3
+ require 'plugin/commands/plugin'
4
+ require 'plugin/commands/discover'
5
+ require 'plugin/commands/info'
6
+ require 'plugin/commands/install'
7
+ require 'plugin/commands/list'
8
+ require 'plugin/commands/remove'
9
+ require 'plugin/commands/source'
10
+ require 'plugin/commands/sources'
11
+ require 'plugin/commands/unsource'
12
+ require 'plugin/commands/update'
@@ -0,0 +1,78 @@
1
+ module Coherent
2
+ module Commands
3
+
4
+ class Discover
5
+ def initialize(base_command)
6
+ @base_command = base_command
7
+ @list = false
8
+ @prompt = true
9
+ end
10
+
11
+ def options
12
+ OptionParser.new do |o|
13
+ o.set_summary_indent(' ')
14
+ o.banner = "Usage: #{@base_command.script_name} discover URI [URI [URI]...]"
15
+ o.define_head "Discover repositories referenced on a page."
16
+ o.separator ""
17
+ o.separator "Options:"
18
+ o.separator ""
19
+ o.on( "-l", "--list",
20
+ "List but don't prompt or add discovered repositories.") { |list| @list, @prompt = list, !@list }
21
+ o.on( "-n", "--no-prompt",
22
+ "Add all new repositories without prompting.") { |v| @prompt = !v }
23
+ end
24
+ end
25
+
26
+ def parse!(args)
27
+ options.parse!(args)
28
+ args = ['http://wiki.rubyonrails.org/rails/pages/Plugins'] if args.empty?
29
+ args.each do |uri|
30
+ scrape(uri) do |repo_uri|
31
+ catch(:next_uri) do
32
+ if @prompt
33
+ begin
34
+ $stdout.print "Add #{repo_uri}? [Y/n] "
35
+ throw :next_uri if $stdin.gets !~ /^y?$/i
36
+ rescue Interrupt
37
+ $stdout.puts
38
+ exit 1
39
+ end
40
+ elsif @list
41
+ puts repo_uri
42
+ throw :next_uri
43
+ end
44
+ Repositories.instance.add(repo_uri)
45
+ puts "discovered: #{repo_uri}" if $verbose or !@prompt
46
+ end
47
+ end
48
+ end
49
+ Repositories.instance.save
50
+ end
51
+
52
+ def scrape(uri)
53
+ require 'open-uri'
54
+ puts "Scraping #{uri}" if $verbose
55
+ dupes = []
56
+ content = open(uri).each do |line|
57
+ begin
58
+ if line =~ /<a[^>]*href=['"]([^'"]*)['"]/ || line =~ /(svn:\/\/[^<|\n]*)/
59
+ uri = $1
60
+ if uri =~ /^\w+:\/\// && uri =~ /\/plugins\// && uri !~ /\/browser\// && uri !~ /^http:\/\/wiki\.rubyonrails/ && uri !~ /http:\/\/instiki/
61
+ uri = extract_repository_uri(uri)
62
+ yield uri unless dupes.include?(uri) || Repositories.instance.exist?(uri)
63
+ dupes << uri
64
+ end
65
+ end
66
+ rescue
67
+ puts "Problems scraping '#{uri}': #{$!.to_s}"
68
+ end
69
+ end
70
+ end
71
+
72
+ def extract_repository_uri(uri)
73
+ uri.match(/(svn|https?):.*\/plugins\//i)[0]
74
+ end
75
+ end
76
+
77
+ end
78
+ end
@@ -0,0 +1,29 @@
1
+ module Coherent
2
+ module Commands
3
+
4
+
5
+ class Info
6
+ def initialize(base_command)
7
+ @base_command = base_command
8
+ end
9
+
10
+ def options
11
+ OptionParser.new do |o|
12
+ o.set_summary_indent(' ')
13
+ o.banner = "Usage: #{@base_command.script_name} info name [name]..."
14
+ o.define_head "Shows plugin info at {url}/about.yml."
15
+ end
16
+ end
17
+
18
+ def parse!(args)
19
+ options.parse!(args)
20
+ args.each do |name|
21
+ puts ::Plugin.find(name).info
22
+ puts
23
+ end
24
+ end
25
+ end
26
+
27
+
28
+ end
29
+ end
@@ -0,0 +1,76 @@
1
+ module Coherent
2
+ module Commands
3
+
4
+
5
+ class Install
6
+ def initialize(base_command)
7
+ @base_command = base_command
8
+ @method = :http
9
+ @options = { :quiet => false, :revision => nil, :force => false }
10
+ end
11
+
12
+ def options
13
+ OptionParser.new do |o|
14
+ o.set_summary_indent(' ')
15
+ o.banner = "Usage: #{@base_command.script_name} install PLUGIN [PLUGIN [PLUGIN] ...]"
16
+ o.define_head "Install one or more plugins."
17
+ o.separator ""
18
+ o.separator "Options:"
19
+ o.on( "-x", "--externals",
20
+ "Use svn:externals to grab the plugin.",
21
+ "Enables plugin updates and plugin versioning.") { |v| @method = :externals }
22
+ o.on( "-o", "--checkout",
23
+ "Use svn checkout to grab the plugin.",
24
+ "Enables updating but does not add a svn:externals entry.") { |v| @method = :checkout }
25
+ o.on( "-e", "--export",
26
+ "Use svn export to grab the plugin.",
27
+ "Exports the plugin, allowing you to check it into your local repository. Does not enable updates, or add an svn:externals entry.") { |v| @method = :export }
28
+ o.on( "-q", "--quiet",
29
+ "Suppresses the output from installation.",
30
+ "Ignored if -v is passed (./script/plugin -v install ...)") { |v| @options[:quiet] = true }
31
+ o.on( "-r REVISION", "--revision REVISION",
32
+ "Checks out the given revision from subversion or git.",
33
+ "Ignored if subversion/git is not used.") { |v| @options[:revision] = v }
34
+ o.on( "-f", "--force",
35
+ "Reinstalls a plugin if it's already installed.") { |v| @options[:force] = true }
36
+ o.separator ""
37
+ o.separator "You can specify plugin names as given in 'plugin list' output or absolute URLs to "
38
+ o.separator "a plugin repository."
39
+ end
40
+ end
41
+
42
+ def determine_install_method
43
+ best = @base_command.environment.best_install_method
44
+ @method = :http if best == :http and @method == :export
45
+ case
46
+ when (best == :http and @method != :http)
47
+ msg = "Cannot install using subversion because `svn' cannot be found in your PATH"
48
+ when (best == :export and (@method != :export and @method != :http))
49
+ msg = "Cannot install using #{@method} because this project is not under subversion."
50
+ when (best != :externals and @method == :externals)
51
+ msg = "Cannot install using externals because vendor/plugins is not under subversion."
52
+ end
53
+ if msg
54
+ puts msg
55
+ exit 1
56
+ end
57
+ @method
58
+ end
59
+
60
+ def parse!(args)
61
+ options.parse!(args)
62
+ environment = @base_command.environment
63
+ install_method = determine_install_method
64
+ puts "Plugins will be installed using #{install_method}" if $verbose
65
+ args.each do |name|
66
+ Coherent::Plugin.find(name).install(install_method, @options)
67
+ end
68
+ rescue StandardError => e
69
+ puts "Plugin not found: #{args.inspect}"
70
+ puts e.inspect if $verbose
71
+ exit 1
72
+ end
73
+ end
74
+
75
+ end
76
+ end
@@ -0,0 +1,55 @@
1
+ module Coherent
2
+ module Commands
3
+
4
+ class List
5
+ def initialize(base_command)
6
+ @base_command = base_command
7
+ @sources = []
8
+ @local = false
9
+ @remote = true
10
+ end
11
+
12
+ def options
13
+ OptionParser.new do |o|
14
+ o.set_summary_indent(' ')
15
+ o.banner = "Usage: #{@base_command.script_name} list [OPTIONS] [PATTERN]"
16
+ o.define_head "List available plugins."
17
+ o.separator ""
18
+ o.separator "Options:"
19
+ o.separator ""
20
+ o.on( "-s", "--source=URL1,URL2", Array,
21
+ "Use the specified plugin repositories.") {|sources| @sources = sources}
22
+ o.on( "--local",
23
+ "List locally installed plugins.") {|local| @local, @remote = local, false}
24
+ o.on( "--remote",
25
+ "List remotely available plugins. This is the default behavior",
26
+ "unless --local is provided.") {|remote| @remote = remote}
27
+ end
28
+ end
29
+
30
+ def parse!(args)
31
+ options.order!(args)
32
+ unless @sources.empty?
33
+ @sources.map!{ |uri| Repository.new(uri) }
34
+ else
35
+ @sources = Repositories.instance.all
36
+ end
37
+ if @remote
38
+ @sources.map{|r| r.plugins}.flatten.each do |plugin|
39
+ if @local or !plugin.installed?
40
+ puts plugin.to_s
41
+ end
42
+ end
43
+ else
44
+ cd "#{@base_command.environment.root}/vendor/plugins"
45
+ Dir["*"].select{|p| File.directory?(p)}.each do |name|
46
+ puts name
47
+ end
48
+ end
49
+ end
50
+ end
51
+
52
+
53
+
54
+ end
55
+ end
@@ -0,0 +1,105 @@
1
+ # load default environment and parse arguments
2
+ module Coherent
3
+ module Commands
4
+
5
+ class Plugin
6
+ attr_reader :environment, :script_name, :sources
7
+ def initialize
8
+ @environment = Coherent::Environment.default
9
+ @root = Coherent::Environment.default.root
10
+ @script_name = File.basename($0)
11
+ @sources = []
12
+ end
13
+
14
+ def environment=(value)
15
+ @environment = value
16
+ Coherent::Environment.default = value
17
+ end
18
+
19
+ def options
20
+ OptionParser.new do |o|
21
+ o.set_summary_indent(' ')
22
+ o.banner = "Usage: #{@script_name} [OPTIONS] command"
23
+ o.define_head "Rails plugin manager."
24
+
25
+ o.separator ""
26
+ o.separator "GENERAL OPTIONS"
27
+
28
+ o.on("-r", "--root=DIR", String,
29
+ "Set an explicit rails app directory.",
30
+ "Default: #{@root}") { |root| @root = root; self.environment = Coherent::Environment.new(@root) }
31
+ o.on("-s", "--source=URL1,URL2", Array,
32
+ "Use the specified plugin repositories instead of the defaults.") { |sources| @sources = sources}
33
+
34
+ o.on("-v", "--verbose", "Turn on verbose output.") { |verbose| $verbose = verbose }
35
+ o.on("-h", "--help", "Show this help message.") { puts o; exit }
36
+
37
+ o.separator ""
38
+ o.separator "COMMANDS"
39
+
40
+ o.separator " discover Discover plugin repositories."
41
+ o.separator " list List available plugins."
42
+ o.separator " install Install plugin(s) from known repositories or URLs."
43
+ o.separator " update Update installed plugins."
44
+ o.separator " remove Uninstall plugins."
45
+ o.separator " source Add a plugin source repository."
46
+ o.separator " unsource Remove a plugin repository."
47
+ o.separator " sources List currently configured plugin repositories."
48
+
49
+ o.separator ""
50
+ o.separator "EXAMPLES"
51
+ o.separator " Install a plugin:"
52
+ o.separator " #{@script_name} install continuous_builder\n"
53
+ o.separator " Install a plugin from a subversion URL:"
54
+ o.separator " #{@script_name} install http://dev.rubyonrails.com/svn/rails/plugins/continuous_builder\n"
55
+ o.separator " Install a plugin from a git URL:"
56
+ o.separator " #{@script_name} install git://github.com/SomeGuy/my_awesome_plugin.git\n"
57
+ o.separator " Install a plugin and add a svn:externals entry to vendor/plugins"
58
+ o.separator " #{@script_name} install -x continuous_builder\n"
59
+ o.separator " List all available plugins:"
60
+ o.separator " #{@script_name} list\n"
61
+ o.separator " List plugins in the specified repository:"
62
+ o.separator " #{@script_name} list --source=http://dev.rubyonrails.com/svn/rails/plugins/\n"
63
+ o.separator " Discover and prompt to add new repositories:"
64
+ o.separator " #{@script_name} discover\n"
65
+ o.separator " Discover new repositories but just list them, don't add anything:"
66
+ o.separator " #{@script_name} discover -l\n"
67
+ o.separator " Add a new repository to the source list:"
68
+ o.separator " #{@script_name} source http://dev.rubyonrails.com/svn/rails/plugins/\n"
69
+ o.separator " Remove a repository from the source list:"
70
+ o.separator " #{@script_name} unsource http://dev.rubyonrails.com/svn/rails/plugins/\n"
71
+ o.separator " Show currently configured repositories:"
72
+ o.separator " #{@script_name} sources\n"
73
+ end
74
+ end
75
+
76
+ def parse!(args=ARGV)
77
+ general, sub = split_args(args)
78
+ options.parse!(general)
79
+
80
+ command = general.shift
81
+ if command =~ /^(list|discover|install|source|unsource|sources|remove|update|info)$/
82
+ command = Commands.const_get(command.capitalize).new(self)
83
+ command.parse!(sub)
84
+ else
85
+ puts "Unknown command: #{command}"
86
+ puts options
87
+ exit 1
88
+ end
89
+ end
90
+
91
+ def split_args(args)
92
+ left = []
93
+ left << args.shift while args[0] and args[0] =~ /^-/
94
+ left << args.shift if args[0]
95
+ return [left, args]
96
+ end
97
+
98
+ def self.parse!(args=ARGV)
99
+ Plugin.new.parse!(args)
100
+ end
101
+ end
102
+
103
+
104
+ end
105
+ end