Sha256: 81f203cd0303d98406a7344270e440a70a19da46f2ad8db32897e8e107424963

Contents?: true

Size: 1.43 KB

Versions: 60

Compression:

Stored size: 1.43 KB

Contents

require 'commands/meta/command'
require 'json'

module Nutella
  # This class describes a template command which can be either install or template
  # It is mostly a commodity class for code reuse.

  class TemplateCommand < Command

    def run (args=nil)
      console.error 'Running generic TemplateCommand!!! WAT?'
    end


    # Validates a template in a certain folder
    # @param [String]  dir the directory where the template is stored
    def validate_template( dir )
      # Parse and validate the template's nutella.json file
      begin
        template_nutella_file_json = JSON.parse(IO.read("#{dir}/nutella.json"))
      rescue
        return false
      end
      return false unless validate_nutella_file_json template_nutella_file_json
      # If template is a bot, perform the appropriate checks
      if template_nutella_file_json['type']=='bot'
        # Is there a mandatory 'startup' script and is it executable
        return false unless File.executable? "#{dir}/startup"
      end
      # If template is an interface, perform the appropriate checks
      if template_nutella_file_json['type']=='interface'
        # Is there the mandatory index.html file
        return false unless File.exist? "#{dir}/index.html"
      end
      true
    end


    def validate_nutella_file_json( json )
      !json['name'].nil? && !json['version'].nil? && !json['type'].nil? && (json['type']=='bot' || json['type']=='interface')
    end


  end

end

Version data entries

60 entries across 60 versions & 1 rubygems

Version Path
nutella_framework-0.9.2 lib/commands/meta/template_command.rb
nutella_framework-0.9.1 lib/commands/meta/template_command.rb
nutella_framework-0.9.0 lib/commands/meta/template_command.rb
nutella_framework-0.8.0 lib/commands/meta/template_command.rb
nutella_framework-0.7.3 lib/commands/meta/template_command.rb
nutella_framework-0.7.2 lib/commands/meta/template_command.rb
nutella_framework-0.7.1 lib/commands/meta/template_command.rb
nutella_framework-0.7.0 lib/commands/meta/template_command.rb
nutella_framework-0.6.21 lib/commands/meta/template_command.rb
nutella_framework-0.6.20 lib/commands/meta/template_command.rb
nutella_framework-0.6.19 lib/commands/meta/template_command.rb
nutella_framework-0.6.18 lib/commands/meta/template_command.rb
nutella_framework-0.6.17 lib/commands/meta/template_command.rb
nutella_framework-0.6.16 lib/commands/meta/template_command.rb
nutella_framework-0.6.15 lib/commands/meta/template_command.rb
nutella_framework-0.6.13 lib/commands/meta/template_command.rb
nutella_framework-0.6.12 lib/commands/meta/template_command.rb
nutella_framework-0.6.11 lib/commands/meta/template_command.rb
nutella_framework-0.6.10 lib/commands/meta/template_command.rb
nutella_framework-0.6.9 lib/commands/meta/template_command.rb