Skip to content

Commit

Permalink
Merge pull request #75 from walkamongus/master
Browse files Browse the repository at this point in the history
Add url helper to internal route links
  • Loading branch information
i11 authored Apr 12, 2018
2 parents 459cbb1 + 099f7b3 commit 67d4144
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 20 deletions.
12 changes: 6 additions & 6 deletions lib/puppet_forge_server/app/frontend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def initialize(root, http_client = PuppetForgeServer::Http::HttpClient.new)
halt(400, haml(:security, :locals => {:query => query})) \
unless safe_input? query

modules = get("#{request.base_url}/v3/modules?query=#{query}")['results']
modules = get("/v3/modules?query=#{query}")['results']
haml :modules, :locals => {:query => query, :modules => modules}
end

Expand All @@ -57,20 +57,20 @@ def initialize(root, http_client = PuppetForgeServer::Http::HttpClient.new)
halt(400, haml(:security, :locals => {:query => module_v3_name})) \
unless safe_input? module_v3_name

releases = get("#{request.base_url}/v3/modules/#{module_v3_name}")['releases']
releases = get("/v3/modules/#{module_v3_name}")['releases']
if params.has_key? 'version'
module_uri = releases.find {|r| r['version'] == params['version']}['uri']
module_metadata = get("#{request.base_url}#{module_uri}")
module_metadata = get("#{module_uri}")
else
module_metadata = get("#{request.base_url}#{releases[0]['uri']}")
module_metadata = get("#{releases[0]['uri']}")
end
begin
readme_markdown = markdown(module_metadata['readme'])
rescue
readme_markdown = ''
end
haml :module, :locals => { :module_metadata => module_metadata,
:base_url => request.base_url,
:base_url => url(request.base_url),
:readme_markdown => readme_markdown,
:releases => releases }
end
Expand All @@ -88,7 +88,7 @@ def initialize(root, http_client = PuppetForgeServer::Http::HttpClient.new)
private
def get(relative_url)
begin
JSON.parse(@http_client.get(relative_url))
JSON.parse(@http_client.get(url(relative_url)))
rescue
{'results' => []}
end
Expand Down
6 changes: 3 additions & 3 deletions lib/puppet_forge_server/app/views/layout.haml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
%title Internal Puppet Forge
-# Latest compiled and minified CSS
%link{ :href => 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css', :type => 'text/css', :rel => 'stylesheet' }
%link{ :href => 'css/puppetlabs.css', :type => 'text/css', :rel => 'stylesheet' }
%link{ :href => url('css/puppetlabs.css'), :type => 'text/css', :rel => 'stylesheet' }
-#%link{ :href => 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap-theme.min.css', :type => 'text/css', :rel => 'stylesheet' }
/[if lt IE 9]
%script{:src => 'https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js'}
Expand Down Expand Up @@ -49,7 +49,7 @@
.side-width.clearfix
%a{:href => url('/')}
#logo
%img.logo{ :src => 'img/forge-logo.png', :height => 65}
%img.logo{ :src => url('img/forge-logo.png'), :height => 65}
%span.logo.puppet= 'Puppet Forge'
%span.logo.forge= 'Server'
.top-search
Expand All @@ -61,4 +61,4 @@
.side-width.clearfix
= yield
%script{ :src => 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js' }
%script{ :src => 'js/internal.js' }
%script{ :src => url('js/internal.js') }
4 changes: 2 additions & 2 deletions lib/puppet_forge_server/app/views/module.haml
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@
%label= 'Select another release: '
%select{:id => 'module-release-selector', :onchange => "location = this.options[this.selectedIndex].value;"}
- releases.each do |release|
%option{:value => "/module?name=#{module_metadata['metadata']['name']}&version=#{release['version']}", :selected => module_metadata['metadata']['version'] == release['version']}= release['version']
%a{:class => 'module-release-download', :href => module_metadata['file_uri'], :title => 'Download module'}= 'Download'
%option{:value => url("/module?name=#{module_metadata['metadata']['name']}&version=#{release['version']}"), :selected => module_metadata['metadata']['version'] == release['version']}= release['version']
%a{:class => 'module-release-download', :href => url(module_metadata['file_uri']), :title => 'Download module'}= 'Download'
%div{:id => 'release-info-tabs', :class => 'module-meta-info'}
%div{:class => 'tabbed content'}
%div
Expand Down
7 changes: 6 additions & 1 deletion lib/puppet_forge_server/models/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ module PuppetForgeServer::Models
class Builder
def initialize(attributes={})
attributes.each do |name, value|
send("#{name}=", value) unless value.to_s.empty?
if name.to_s == 'decription'
normalized_name = :description
else
normalized_name = name.to_s.tr('-', '_').to_sym
end
send("#{normalized_name}=", value) unless value.to_s.empty?
end
end

Expand Down
17 changes: 9 additions & 8 deletions lib/puppet_forge_server/models/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,24 @@
# See the License for the specific language governing permissions and
# limitations under the License.


module PuppetForgeServer::Models
class Metadata < Builder

attr_accessor :author, :name, :version, :dependencies, :summary, :description, :project_page, :types
attr_accessor :checksums, :source, :license, :issues_url, :operatingsystem_support, :requirements
attr_accessor :puppet_version, :tags, :mail, :classes, :definitions
attr_accessor :pdk_version, :template_url, :template_ref, :data_provider, :docs_project
attr_accessor :forge_url, :package_release_version, :issue_url
attr_accessor :kpn_quality_label, :kpn_module_owner, :kpn_module_support

def initialize(attributes)
super(attributes)
end

def ==(other)
other && self.class.equal?(other.class) &&
@author == other.author &&
@name == other.name &&
@version == other.version
@author == other.author &&
@name == other.name &&
@version == other.version
end

def hash
Expand All @@ -39,9 +40,9 @@ def hash

def eql?(other)
other && self.class.equal?(other.class) &&
@author.eql?(other.author) &&
@name.eql?(other.name) &&
@version.eql?(other.version)
@author.eql?(other.author) &&
@name.eql?(other.name) &&
@version.eql?(other.version)
end
end
end

0 comments on commit 67d4144

Please sign in to comment.