-
Notifications
You must be signed in to change notification settings - Fork 20
Added module documentation visualization and fixed haml top bar. Added "--modulepath" option to the library. #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
f8db968
eec2607
146da3a
3d3e5a9
a8ec08d
1ab3f47
39f21c3
6b43232
c2200aa
0187000
e5baa1b
14b75be
0d707ff
b9a6145
3f1e0a7
ee262d9
a4dca38
a84cef1
a50db20
72e5064
5a70c7f
0f5c619
e60b247
8d763f8
09dae28
93a8c78
a5123cf
49d102a
e5cd223
aad1b9b
6a0d539
e2bbf1a
e0694a1
86c93b7
5d6b542
6b46dc5
c2b009e
f846f8c
6853242
9326487
764e9f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,3 +17,4 @@ test/version_tmp | |
| tmp | ||
| .rake_t_cache | ||
| /Gemfile.lock | ||
| .DS_Store | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,7 +27,7 @@ | |
| %style | ||
| :plain | ||
| body { | ||
| padding-top: 50px; | ||
| padding-top: 100px; | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,3 +23,8 @@ | |
| %ul | ||
| - metadata["releases"].each do |release| | ||
| %li= release["version"] | ||
|
|
||
|
|
||
| %hr | ||
|
|
||
| %div= metadata["documentation"] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,13 @@ def initialize(path) | |
| @path = path | ||
| end | ||
|
|
||
| def check_entry?(entry_name_regex) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
||
| 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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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" | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,6 +76,7 @@ module PuppetLibrary::Forge | |
| "name"=>"apache", | ||
| "desc"=>"Puppet module for Apache", | ||
| "project_url"=>"https://github.com/puppetlabs/puppetlabs-apache", | ||
| "documentation" => nil, | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"] | ||
|
|
@@ -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, | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Necessary for new tests! |
||
| "version"=>"1.0.0", | ||
| "tag_list"=>["dodgybrothers", "ntp"] | ||
| }] | ||
|
|
@@ -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, | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Necessary for new tests! |
||
| "version"=>"1.0.0", | ||
| "tag_list"=>["puppetlabs", "apache"] | ||
| }] | ||
|
|
@@ -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, | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Necessary for new tests! |
||
| "version"=>"0.10.0", | ||
| "tag_list"=>["puppetlabs", "apache"] | ||
| },{ | ||
|
|
@@ -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, | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Necessary for new tests! |
||
| "version"=>"1.0.0", | ||
| "tag_list"=>["dodgybrothers", "ntp"] | ||
| }] | ||
|
|
||
There was a problem hiding this comment.
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.