lib/ronin/generators/platform/overlay.rb in ronin-gen-0.1.0 vs lib/ronin/generators/platform/overlay.rb in ronin-gen-0.1.1

- old
+ new

@@ -45,10 +45,19 @@ LIB_DIR = Ronin::Platform::Overlay::LIB_DIR # The Overlay objects directory OBJECTS_DIR = Ronin::Platform::Overlay::OBJECTS_DIR + # Default license to use + DEFAULT_LICENSE = 'CC-by' + + # Default maintainer to use + DEFAULT_MAINTAINER = {:name => 'Name', :email => 'name@example.com'} + + # Default description to use + DEFAULT_DESCRIPTION = 'This is an Overlay' + # Title of the overlay attr_accessor :title # Source URL for the overlay attr_accessor :source @@ -77,27 +86,30 @@ # _options_ may include the following keys: # <tt>:title</tt>:: Title for the overlay. # <tt>:source</tt>:: Source URL for the overlay. # <tt>:source_view</tt>:: Source View URL for the overlay. # <tt>:website</tt>:: Website for the overlay. - # <tt>:license</tt>:: License for the overlay. + # <tt>:license</tt>:: License for the overlay. Defaults to + # DEFUALT_LICENSE, if not given. # <tt>:maintainers</tt>:: List of maintainers for the overlay. # <tt>:description</tt>:: The description of the overlay. + # Defaults to DEFAULT_DESCRIPTION, + # if not given. # def initialize(options={}) @title = options[:title] @source = options[:source] @source_view = options[:source_view] @website = options[:website] - @license = options[:license] + @license = (options[:license] || DEFAULT_LICENSE) @maintainers = [] if options[:maintainers] @maintainers.merge!(options[:maintainers]) end - @description = options[:description] + @description = (options[:description] || DEFAULT_DESCRIPTION) @tasks = Set[] if options[:tasks] @tasks.merge!(options[:tasks]) end @@ -117,12 +129,15 @@ # def generate! @title ||= File.basename(@path).gsub(/[_\s]+/,' ').capitalize @source_view ||= @source @website ||= @source_view + @maintainers << DEFAULT_MAINTAINER if @maintainers.empty? directory LIB_DIR + touch File.join(LIB_DIR,Ronin::Platform::Overlay::INIT_FILE) + directory OBJECTS_DIR directory 'tasks' generate_rakefile! generate_metadata! @@ -178,46 +193,40 @@ url_tag = XML::Node.new('website',doc) url_tag << XML::Text.new(@website,doc) root << url_tag end - if @license - license_tag = XML::Node.new('license',doc) - license_tag << XML::Text.new(@license,doc) - root << license_tag - end + license_tag = XML::Node.new('license',doc) + license_tag << XML::Text.new(@license,doc) + root << license_tag - unless @maintainers.empty? - maintainers_tag = XML::Node.new('maintainers',doc) + maintainers_tag = XML::Node.new('maintainers',doc) - @maintainers.each do |author| - if (author[:name] || author[:email]) - maintainer_tag = XML::Node.new('maintainer',doc) + @maintainers.each do |author| + if (author[:name] || author[:email]) + maintainer_tag = XML::Node.new('maintainer',doc) - if author[:name] - name_tag = XML::Node.new('name',doc) - name_tag << XML::Text.new(author[:name],doc) - maintainer_tag << name_tag - end + if author[:name] + name_tag = XML::Node.new('name',doc) + name_tag << XML::Text.new(author[:name],doc) + maintainer_tag << name_tag + end - if author[:email] - email_tag = XML::Node.new('email',doc) - email_tag << XML::Text.new(author[:email],doc) - maintainer_tag << email_tag - end - - maintainers_tag << maintainer_tag + if author[:email] + email_tag = XML::Node.new('email',doc) + email_tag << XML::Text.new(author[:email],doc) + maintainer_tag << email_tag end - end - root << maintainers_tag + maintainers_tag << maintainer_tag + end end - if @description - description_tag = XML::Node.new('description',doc) - description_tag << XML::Text.new(@description,doc) - root << description_tag - end + root << maintainers_tag + + description_tag = XML::Node.new('description',doc) + description_tag << XML::Text.new(@description,doc) + root << description_tag doc << root doc.write_xml_to(metadata_file) end end