Skip to content

Commit

Permalink
Added drawing of a tree of extensions, plugins, radiant + plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
netzpirat committed Jan 26, 2009
1 parent ace69cc commit de61ad2
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 43 deletions.
46 changes: 46 additions & 0 deletions lib/helper/tree.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
class Tree

#
# Show the tree representation of the project
#
def self.show(project)
print "#{project.to_s}"

# Project type
if project.radiant?
puts " (Radiant Project)"
else
puts " (Rails Project)"
end

# Radiant extensions
if project.extensions?
puts '+-extensions'
project.extensions.each do |extension|
puts " +-#{extension.to_s}"
end
end

# Plugins
if project.plugins?
puts '+-plugins'
project.plugins.each do |plugin|
puts " +-#{plugin.to_s}"
end
end

# Radiant in vendor
if project.radiant
puts '+-radiant'
# Radiant Plugins
if project.radiant_plugins?
puts ' +-plugins'
project.radiant_plugins.each do |plugin|
puts " +-#{plugin.to_s}"
end
end
end

end

end
18 changes: 2 additions & 16 deletions lib/subito.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,13 @@
require 'pathname'
require 'subito/project'
require 'subito/submodule'
require 'helper/tree'

class Subito < Thor

desc 'show', 'shows all submodules'
def show
project = Project.new
puts project.to_s

if project.extensions?
puts '+-extension'
project.extensions.each do |extension|
puts " +-#{extension.to_s}"
end
end

if project.plugins?
puts '+-plugin'
project.plugins.each do |plugin|
puts " +-#{plugin.to_s}"
end
end
Tree.show(Project.new)
end

end
56 changes: 42 additions & 14 deletions lib/subito/project.rb
Original file line number Diff line number Diff line change
@@ -1,47 +1,75 @@
class Project

attr_reader :root, :submodules, :extensions, :plugins
attr_reader :root, :submodules, :extensions, :plugins, :radiant, :radiant_plugins

ENVIRONMENT = 'config/environment.rb'

#
# Initialize a radiant project:
# Initialize a rails/radiant project:
# * Find project root
# * Find submodules
# * Find submodules and classify by type
#
def initialize
@root = Project.find_radiant_root(Pathname.pwd)
@root = Project.find_rails_root(Pathname.pwd)
@submodules = find_submodules
@extensions = @submodules.select { |s| s.extension? }
@plugins = @submodules.select { |s| s.plugin? }
@plugins = @submodules.select { |s| s.plugin? && !s.radiant_vendor? }
@radiant =@submodules.select { |s| s.radiant? }
@radiant_plugins = @submodules.select { |s| s.plugin? && s.radiant_vendor? }
end

#
# Does the project has any extensions as submodule installed?
#
def extensions?
!@extensions.empty?
end

#
# Does the project has any plugins as submodule installed?
#
def plugins?
!@plugins.empty?
end

#
# Does the project has any plugins in vendor/radiant as submodule installed?
#
def radiant_plugins?
!@radiant_plugins.empty?
end

#
# Is it a radiant project
#
def radiant?
File.open(@root + ENVIRONMENT).grep(/Radiant::Initializer/) do |line|
return true
end
false
end

#
# Name of the project
#
def to_s
@root.basename
end

private

#
# Traverses the actual directory up until it finds the radiant root or
# throws an execption if the file system root has been reached without
# finding the radiant root.
# Traverses the actual directory up until it finds the rails root.
# Exits if the file system root has been reached.
#
def self.find_radiant_root(directory=Pathname.new($0))
def self.find_rails_root(directory)

# check for radiant initializer in the environment file
env_file = directory + 'config/environment.rb'
return directory if File.exists?(env_file) &&
File.open(env_file).grep(/Radiant::Initializer/)
env_file = directory + ENVIRONMENT
return directory if File.exists?(env_file)

if directory.root?
puts 'Error: Subito has to run inside a Radiant project!'
puts 'Error: Subito has to run inside a Rails or Radiant project!'
exit 1
end

Expand All @@ -50,7 +78,7 @@ def self.find_radiant_root(directory=Pathname.new($0))
end

#
# Returns all submodules of the radiant project
# Returns all submodules of the project
#
def find_submodules
Dir.chdir(@root) do
Expand Down
56 changes: 43 additions & 13 deletions lib/subito/submodule.rb
Original file line number Diff line number Diff line change
@@ -1,31 +1,61 @@
class Submodule

attr_reader :root
attr_reader :git, :root

def initialize(root)
@root = root.parent
#
# Initialize a new submodule
#
# +git+ the git directory of the submodule
#
def initialize(git)
@git = git
@root = git.parent
end

#
# Is the submodule an installed radiant extension?
#
def extension?
type.to_s == 'extensions'
type == 'extensions'
end


#
# Is the submodule a plugin?
#
def plugin?
type.to_s == 'plugins'
end

def gem?
type.to_s == 'gems'
type == 'plugins'
end

#
# Is the submodule the Radiant submodule?
#
def radiant?
type.to_s == 'radiant'
type == 'radiant'
end


#
# Type of the submodule. Is either one of
# * extension
# * plugin
# * radiant
#
def type
@root.parent.basename
@root.parent.basename.to_s
end

#
# Is the submodule installed in the radiant vendor folder
#
def radiant_vendor?
begin
@root.parent.parent.parent.basename.to_s == 'radiant'
rescue
end
end

#
# Name of the submodule
#
def to_s
@root.basename
end
Expand Down

0 comments on commit de61ad2

Please sign in to comment.