Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
f8db968
Added documentation when opening a module information screen
Jul 9, 2014
eec2607
Added --modulepath option successfully
moliholy Jul 19, 2014
146da3a
Added Modulefile compatibility
moliholy Jul 19, 2014
3d3e5a9
Sorting search results alphabetically and displaying modules with wro…
moliholy Jul 22, 2014
a8ec08d
Fixed library files
Aug 4, 2014
1ab3f47
Added UTF-8 encoding to HTML documentation
moliholy Aug 5, 2014
39f21c3
Not raising an exception when there is no concrete file in a tar.gz m…
moliholy Aug 6, 2014
6b43232
Fixed specs to pass test with the new features
moliholy Aug 6, 2014
c2200aa
Fixed specs to pass test with the new features
moliholy Aug 6, 2014
0187000
Fixed specs to pass test with the new features
moliholy Aug 6, 2014
e5baa1b
Fixed specs to pass test with the new features
moliholy Aug 6, 2014
14b75be
Merge branch 'master' of github.com:Moliholy/puppet-library
Aug 8, 2014
0d707ff
Added documentation when opening a module information screen
Jul 9, 2014
b9a6145
Added --modulepath option successfully
moliholy Jul 19, 2014
3f1e0a7
Added Modulefile compatibility
moliholy Jul 19, 2014
ee262d9
Sorting search results alphabetically and displaying modules with wro…
moliholy Jul 22, 2014
a4dca38
Fixed library files
Aug 4, 2014
a84cef1
Added UTF-8 encoding to HTML documentation
moliholy Aug 5, 2014
a50db20
Not raising an exception when there is no concrete file in a tar.gz m…
moliholy Aug 6, 2014
72e5064
Fixed specs to pass test with the new features
moliholy Aug 6, 2014
5a70c7f
Fixed specs to pass test with the new features
moliholy Aug 6, 2014
0f5c619
Fixed specs to pass test with the new features
moliholy Aug 6, 2014
e60b247
Merge branch 'master' of github.com:Moliholy/puppet-library
Aug 8, 2014
8d763f8
Merge branch 'master' of github.com:Moliholy/puppet-library
Aug 8, 2014
09dae28
Merge branch 'master' of github.com:Moliholy/puppet-library
Aug 8, 2014
93a8c78
Merge branch 'master' of github.com:Moliholy/puppet-library
Aug 8, 2014
a5123cf
Merge branch 'master' of https://github.com/Moliholy/puppet-library
Aug 8, 2014
49d102a
Fixed minor syntax error
moliholy Aug 8, 2014
e5cd223
Fixed minor syntax error
moliholy Aug 8, 2014
aad1b9b
Merge branch 'master' of https://github.com/Moliholy/puppet-library
Aug 8, 2014
6a0d539
Fixed files permissions
Aug 11, 2014
e2bbf1a
Fixed files permissions
Aug 11, 2014
e0694a1
Merge branch 'master' of https://github.com/Moliholy/puppet-library
Aug 11, 2014
86c93b7
Merge branch 'master' of https://github.com/Moliholy/puppet-library
Aug 11, 2014
5d6b542
Merge branch 'master' of https://github.com/Moliholy/puppet-library
Aug 12, 2014
6b46dc5
Merge branch 'master' of https://github.com/Moliholy/puppet-library
Aug 12, 2014
c2b009e
Merge branch 'master' of https://github.com/Moliholy/puppet-library
Aug 12, 2014
f846f8c
Merge branch 'master' of https://github.com/Moliholy/puppet-library
Aug 12, 2014
6853242
Merge branch 'master' of https://github.com/Moliholy/puppet-library
Aug 12, 2014
9326487
Merge branch 'master' of https://github.com/Moliholy/puppet-library
Aug 12, 2014
764e9f4
Merge branch 'master' of https://github.com/Moliholy/puppet-library
Aug 12, 2014
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ test/version_tmp
tmp
.rake_t_cache
/Gemfile.lock
.DS_Store
7 changes: 7 additions & 0 deletions lib/puppet_library/app/views/index.haml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
$(document).ready(function() {
var source = "modules.json#{ query.nil? ? '' : '?q=' + query }";
$.getJSON(source, function(modules) {

modules.sort(function(a, b){
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It sorts all modules by full name. I tried to do it in the server but because of problems with ruby versions it ended up being a pain in the neck, so it's finally the client who is going to do it.

var aFull_name = a.full_name.toLowerCase();
var bFull_name = b.full_name.toLowerCase();
return ((aFull_name < bFull_name) ? -1 : ((aFull_name > bFull_name) ? 1 : 0));
});

$.each(modules, function(index, module) {
var item = $("<li/>");
item.append($("<b/>").append($("<a/>").attr("href", module.full_name).text(module.full_name)));
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet_library/app/views/layout.haml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
%style
:plain
body {
padding-top: 50px;
padding-top: 100px;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a problem visualising the main title because of the top bar. With this it is fixed.

}
input.search-query {
padding-left:32px;
Expand Down
5 changes: 5 additions & 0 deletions lib/puppet_library/app/views/module.haml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@
%ul
- metadata["releases"].each do |release|
%li= release["version"]


%hr

%div= metadata["documentation"]
7 changes: 7 additions & 0 deletions lib/puppet_library/archive/archive_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ def initialize(path)
@path = path
end

def check_entry?(entry_name_regex)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function checks if there is a file in the compressed module. Concretely here I search for a README, README.md or README.markdown files to display the documentation.

tar = Gem::Package::TarReader.new(Zlib::GzipReader.open(@path))
tar.rewind
entry = tar.find {|e| e.full_name =~ entry_name_regex }
!entry.nil?
end

def read_entry(entry_name_regex)
tar = Gem::Package::TarReader.new(Zlib::GzipReader.open(@path))
tar.rewind
Expand Down
1 change: 1 addition & 0 deletions lib/puppet_library/forge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class ModuleNotFound < Exception
require 'puppet_library/forge/abstract'
require 'puppet_library/forge/cache'
require 'puppet_library/forge/directory'
require 'puppet_library/forge/source_directory'
require 'puppet_library/forge/forge'
require 'puppet_library/forge/git_repository'
require 'puppet_library/forge/multi'
Expand Down
8 changes: 7 additions & 1 deletion lib/puppet_library/forge/abstract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,18 @@ def dependency_names
dependencies.map {|d| d["name"]}
end

def documentation
@metadata["documentation"]
end

def to_info
{
"author" => author,
"full_name" => full_name,
"name" => name,
"desc" => description,
"releases" => [ { "version" => version } ]
"releases" => [ { "version" => version } ],
"documentation" => documentation
}
end

Expand All @@ -182,6 +187,7 @@ def to_search_result
"desc" => summary,
"project_url" => project_page,
"releases" => [{ "version" => version}],
"documentation" => documentation,
"version" => version,
"tag_list" => [author, name]
}
Expand Down
13 changes: 12 additions & 1 deletion lib/puppet_library/forge/directory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

require 'json'
require 'redcarpet'
require 'puppet_library/forge/abstract'
require 'puppet_library/archive/archive_reader'
require 'puppet_library/util/config_api'
Expand Down Expand Up @@ -78,7 +79,17 @@ def get_metadata(author, module_name)
def read_metadata(archive_path)
archive = PuppetLibrary::Archive::ArchiveReader.new(archive_path)
metadata_file = archive.read_entry %r[[^/]+/metadata\.json$]
JSON.parse(metadata_file)
parsedJSON = JSON.parse(metadata_file)

readme_regex = %r[/README[\.(md|markdown)]]
if archive.check_entry? readme_regex
readmeText = archive.read_entry readme_regex
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML.new(:with_tocdata => true), extensions = {})
readmeHTML = markdown.render(readmeText).force_encoding("UTF-8")
parsedJSON["documentation"] = readmeHTML
end
parsedJSON

rescue => error
warn "Error reading from module archive #{archive_path}: #{error}"
return nil
Expand Down
123 changes: 123 additions & 0 deletions lib/puppet_library/forge/source_directory.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# -*- encoding: utf-8 -*-
# Puppet Library
# Copyright (C) 2014 drrb
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

require 'json'
require 'redcarpet'
require 'puppet_library/forge/abstract'
require 'puppet_library/util/config_api'

module PuppetLibrary::Forge

# A forge that serves modules in unpacked format from a directory on disk.
#
# <b>Note:</b>
# * The modules must be in unpacked format
# * The modules (directories) must be named in the format <tt>modulename</tt>
# * The modules must contain a +metadata.json+ file
#
# <b>Usage:</b>
#
# forge = PuppetLibrary::Forge::SourceDirectory.configure do
# # The path to serve the modules from
# path "/var/modules/cache"
# end
class SourceDirectory < PuppetLibrary::Forge::Abstract
def self.configure(&block)
config_api = PuppetLibrary::Util::ConfigApi.for(SourceDirectory) do
required :path, "path to the modules' source" do |path|
Dir.new(File.expand_path(path))
end
end
config = config_api.configure(&block)
SourceDirectory.new(config.get_path)
end

# * <tt>:module_dir</tt> - The directory containing the unpackaged modules.
def initialize(module_dir)
super(self)
@module_dir = module_dir
end

def get_module(author, name, version)
file_name = "#{name}"
path = File.join(@module_dir.path, file_name)
if File.exist? path
File.open(path, 'r:UTF-8')
else
nil
end
end

def get_all_metadata
get_metadata("*","*")

end

def get_metadata(author, module_name)
archives = Dir["#{@module_dir.path}/*#{module_name}*"]
archives.map {|path| read_metadata(path) }.compact
end

private
def read_metadata(directory_path)
metadata_file_path = File.join(directory_path, "metadata.json")
modulefile_path = File.join(directory_path, "Modulefile")

if File.exist?(metadata_file_path)
metadata_file = File.open(metadata_file_path, "r:UTF-8").read
parsedJSON = JSON.parse(metadata_file)
elsif File.exist?(modulefile_path)
parsedJSON = PuppetLibrary::PuppetModule::Modulefile.read(modulefile_path).to_metadata
else
return nil
end

Dir.chdir("#{directory_path}")

# firstly trying to get the README.md file
readmePath = Dir["README.md"].last

if readmePath.nil? || !File.exist?(readmePath)
readmePath = Dir["README*"].last
end

if !readmePath.nil? && File.exist?(readmePath)
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML.new(:with_toc_data => true), extensions = {})
readmeText = File.open("#{directory_path}/#{readmePath}").read
readmeHTML = markdown.render(readmeText)
parsedJSON["documentation"] = readmeHTML
end

parsedJSON

rescue => error
warn "Error reading from module archive #{directory_path}: #{error.backtrace.join("\n")}"
return {
"name" => "unknown/#{directory_path.split("/").last}",
"version" => "unknown",
"source" => "unknown",
"author" => "unknown",
"license" => "unknown",
"summary" => "unknown",
"description" => "unknown",
"project_page" => "unknown",
"dependencies" => "unknown",
"documentation" => nil
}
end
end
end
8 changes: 7 additions & 1 deletion lib/puppet_library/puppet_library.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
require 'optparse'
require 'rack'
require 'yaml'
require 'puppet_library/forge/source_directory'
require 'puppet_library/forge/directory'
require 'puppet_library/forge/multi'
require 'puppet_library/forge/proxy'
Expand Down Expand Up @@ -86,6 +87,11 @@ def parse_options(args)
opts.on("--cache-basedir DIR", "Cache all proxies' downloaded modules under this directory") do |cache_basedir|
options[:cache_basedir] = cache_basedir
end

#new option --modulepath
opts.on("--modulepath DIR", "Directory containing all module's sources") do |modulepath|
options[:forges] << [Forge::SourceDirectory, modulepath]
end
end
begin
option_parser.parse(args)
Expand Down Expand Up @@ -161,7 +167,7 @@ def load_defaults!(options)

def process_options!(options)
options[:forges].map! do |(forge_type, config)|
if [ Forge::Directory, Forge::Source ].include? forge_type
if [ Forge::Directory, Forge::Source, Forge::SourceDirectory ].include? forge_type
[ forge_type, [ Dir.new(sanitize_path(config)) ]]
elsif forge_type == Forge::Proxy && options[:cache_basedir]
cache_dir = File.join(options[:cache_basedir], url_hostname(config))
Expand Down
1 change: 1 addition & 0 deletions puppet-library.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Gem::Specification.new do |spec|
spec.add_dependency "haml"
spec.add_dependency "docile", ">= 1.0.0"
spec.add_dependency "open4"
spec.add_dependency "redcarpet", "~> 2.3.0"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2.3.0 is necessary for Ruby 1.8.7 compatibility.


spec.add_development_dependency "bundler", "~> 1.3"
spec.add_development_dependency "coveralls"
Expand Down
5 changes: 5 additions & 0 deletions spec/forge/abstract_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ module PuppetLibrary::Forge
"name"=>"apache",
"desc"=>"Puppet module for Apache",
"project_url"=>"https://github.com/puppetlabs/puppetlabs-apache",
"documentation" => nil,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Necessary for new tests!

"releases"=>[{"version"=>"0.10.0"}],
"version"=>"0.10.0",
"tag_list"=>["puppetlabs", "apache"]
Expand All @@ -91,6 +92,7 @@ module PuppetLibrary::Forge
"desc"=>"Puppet module for NTP",
"project_url"=>"https://github.com/dodgybrothers/puppet-ntp",
"releases"=>[{"version"=>"1.0.0"}],
"documentation" => nil,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Necessary for new tests!

"version"=>"1.0.0",
"tag_list"=>["dodgybrothers", "ntp"]
}]
Expand Down Expand Up @@ -127,6 +129,7 @@ module PuppetLibrary::Forge
"desc"=>"New Puppet module for Apache",
"project_url"=>"https://github.com/puppetlabs/puppetlabs-apache-new",
"releases"=>[{"version"=>"1.0.0"},{"version"=>"0.10.0"}],
"documentation" => nil,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Necessary for new tests!

"version"=>"1.0.0",
"tag_list"=>["puppetlabs", "apache"]
}]
Expand All @@ -145,6 +148,7 @@ module PuppetLibrary::Forge
"desc"=>"Puppet module for Apache",
"project_url"=>"https://github.com/puppetlabs/puppetlabs-apache",
"releases"=>[{"version"=>"0.10.0"}],
"documentation" => nil,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Necessary for new tests!

"version"=>"0.10.0",
"tag_list"=>["puppetlabs", "apache"]
},{
Expand All @@ -154,6 +158,7 @@ module PuppetLibrary::Forge
"desc"=>"Puppet module for NTP",
"project_url"=>"https://github.com/dodgybrothers/puppet-ntp",
"releases"=>[{"version"=>"1.0.0"}],
"documentation" => nil,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Necessary for new tests!

"version"=>"1.0.0",
"tag_list"=>["dodgybrothers", "ntp"]
}]
Expand Down