Class: Jdt::Manifest

Inherits:
Object
  • Object
show all
Defined in:
lib/jdt/manifest/bump.rb,
lib/jdt/manifest/find.rb,
lib/jdt/manifest/build.rb,
lib/jdt/manifest/secure.rb,
lib/jdt/manifest/manifest.rb,
lib/jdt/manifest/attributes.rb,
lib/jdt/manifest/referenced.rb,
lib/jdt/manifest/validation.rb

Direct Known Subclasses

LibraryManifest

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Manifest

Returns a new instance of Manifest.



9
10
11
12
# File 'lib/jdt/manifest/manifest.rb', line 9

def initialize(path)
  @file = path
  @doc = Nokogiri::XML(File.read(file))
end

Instance Attribute Details

#docObject

Returns the value of attribute doc.



7
8
9
# File 'lib/jdt/manifest/manifest.rb', line 7

def doc
  @doc
end

#errorsObject

Returns the value of attribute errors.



7
8
9
# File 'lib/jdt/manifest/validation.rb', line 7

def errors
  @errors
end

#fileObject

Returns the value of attribute file.



7
8
9
# File 'lib/jdt/manifest/manifest.rb', line 7

def file
  @file
end

#warningsObject

Returns the value of attribute warnings.



7
8
9
# File 'lib/jdt/manifest/validation.rb', line 7

def warnings
  @warnings
end

Class Method Details

.find(path = ".") ⇒ Object



7
8
9
# File 'lib/jdt/manifest/find.rb', line 7

def self.find(path = ".")
  Manifest.new(ManifestFinder.new(path).find).to_specific
end

Instance Method Details

#authorObject



19
20
21
# File 'lib/jdt/manifest/attributes.rb', line 19

def author
  @doc.xpath("//extension/author").text
end

#author_emailObject



23
24
25
# File 'lib/jdt/manifest/attributes.rb', line 23

def author_email
  @doc.xpath("//extension/authorEmail").text
end

#author_urlObject



27
28
29
# File 'lib/jdt/manifest/attributes.rb', line 27

def author_url
  @doc.xpath("//extension/authorUrl").text
end

#buildObject



7
8
9
# File 'lib/jdt/manifest/build.rb', line 7

def build
  ExtensionZipper.new(self).zip(:build)
end

#bump!(type) ⇒ Object



7
8
9
10
11
# File 'lib/jdt/manifest/bump.rb', line 7

def bump!(type)
  new_version = bump_version(type, version)
  @doc.at_css("extension > version").content = new_version
  update_file_with_doc
end


59
60
61
# File 'lib/jdt/manifest/attributes.rb', line 59

def copyright
  @doc.xpath("//extension/copyright").text
end

#creation_dateObject



31
32
33
# File 'lib/jdt/manifest/attributes.rb', line 31

def creation_date
  @doc.xpath("//extension/creationDate").text
end

#descriptionObject



47
48
49
# File 'lib/jdt/manifest/attributes.rb', line 47

def description
  @doc.xpath("//extension/description").text
end

#exists?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/jdt/manifest/manifest.rb', line 23

def exists?
  File.exists?(file)
end

#ext_methodObject



15
16
17
# File 'lib/jdt/manifest/attributes.rb', line 15

def ext_method
  @doc.xpath("//extension").first['method']
end

#ext_typeObject



71
72
73
# File 'lib/jdt/manifest/attributes.rb', line 71

def ext_type
  @doc.xpath("//extension").first['type']
end

#ext_type_shortObject

Raises:

  • (NoMethodError)


67
68
69
# File 'lib/jdt/manifest/attributes.rb', line 67

def ext_type_short
  raise NoMethodError
end

#folderObject



19
20
21
# File 'lib/jdt/manifest/manifest.rb', line 19

def folder
  File.dirname(file)
end

#homepageObject



55
56
57
# File 'lib/jdt/manifest/attributes.rb', line 55

def homepage
  @doc.xpath("//extension/homepage").text
end

#licenseObject



63
64
65
# File 'lib/jdt/manifest/attributes.rb', line 63

def license
  @doc.xpath("//extension/license").text
end

#nameObject



35
36
37
# File 'lib/jdt/manifest/attributes.rb', line 35

def name
  @doc.xpath("//extension/name").text
end

#prefixed_nameObject



39
40
41
# File 'lib/jdt/manifest/attributes.rb', line 39

def prefixed_name
  "#{ext_type_short}_#{name}"
end

#prefixed_name_with_versionObject



43
44
45
# File 'lib/jdt/manifest/attributes.rb', line 43

def prefixed_name_with_version
  "#{prefixed_name}-v#{version}"
end

#referencedObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/jdt/manifest/referenced.rb', line 5

def referenced

  list = []

  # add files and media
  @doc.css("files","media").each do |files|

    parent_folder = files['folder']

    files.css("filename").each do |file|
      list << create_file_ref(file.text,parent_folder)
    end

    files.css("folder").each do |file|
      list << create_folder_ref(file.text,parent_folder)
    end

  end

  # scriptfile
  @doc.css("scriptfile").each do |file|
    list << create_file_ref(file.text)
  end

  return list
end

#releaseObject



11
12
13
# File 'lib/jdt/manifest/build.rb', line 11

def release
  ExtensionZipper.new(self).zip(:release)
end

#required_joomla_versionObject



11
12
13
# File 'lib/jdt/manifest/attributes.rb', line 11

def required_joomla_version
  @doc.xpath("//extension").first['version']
end

#secureObject



7
8
9
10
11
# File 'lib/jdt/manifest/secure.rb', line 7

def secure
  "do nothing"
  # TODO check if every file with the ending .php contains the line::::: defined('_JEXEC') or die('Restricted access');
  # TODO if not, insert this directly after the line containing <?php within the file, including the comment: //No direct access to this file and print which files have been changed.   
end

#to_specificObject



11
12
13
14
15
16
17
# File 'lib/jdt/manifest/find.rb', line 11

def to_specific
  if (ext_type == "library")
    LibraryManifest.new(file)
  else
    raise RuntimeError("the current type #{ext_type} is not supported")
  end
end

#to_xmlObject



14
15
16
17
# File 'lib/jdt/manifest/manifest.rb', line 14

def to_xml
  xsl = Nokogiri::XSLT(File.read("#{File.dirname(File.expand_path(__FILE__))}/xslts/pretty_print.xsl"))
  xsl.transform(@doc).to_s
end

#valid?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/jdt/manifest/validation.rb', line 9

def valid?
  syntax_valid? and semantics_valid?
end

#versionObject



51
52
53
# File 'lib/jdt/manifest/attributes.rb', line 51

def version
  @doc.xpath("//extension/version").text
end