Main repository for Devuan's www.devuan.org.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

163 lines
4.3 KiB

  1. module DevuanHelpers
  2. PROJECT_URL = "https://git.devuan.org/devuan-editors/devuan-www"
  3. GIT_BRANCH = "beta.devuan.org"
  4. EDIT_URL = "#{PROJECT_URL}/edit/#{GIT_BRANCH}/source"
  5. SRC_URL = "#{PROJECT_URL}/tree/#{GIT_BRANCH}/source"
  6. def relative_source_path
  7. current_page.source_file.split('/source')[1]
  8. end
  9. # Override link_to to check for external links
  10. # and add target: _blank (#98) + rel="nofollow"
  11. def link_to(*args, &block)
  12. options = args.extract_options!
  13. name = block_given? ? '' : args.shift
  14. href = args.first
  15. if href =~ %r[^https?://] # skip local links
  16. host = href.split('/')[2]
  17. unless host =~ /devuan\.org$/
  18. options.reverse_merge!(:target => '_blank', :rel => 'nofollow')
  19. end
  20. end
  21. super(*[name, href, options.empty? ? nil : options].compact, &block)
  22. end
  23. def link_to_edit_page
  24. link_to(t(:edit), File.join(EDIT_URL, relative_source_path))
  25. end
  26. def link_to_source
  27. link_to(t(:view_source), File.join(SRC_URL, relative_source_path))
  28. end
  29. def link_to_new_issue
  30. link_to(t(:issues), "#{PROJECT_URL}/issues/new?issue[label_ids][]=1291&issue[title]=#{current_page.url}")
  31. end
  32. def mirror_countries(mirrors)
  33. countries = []
  34. (mirrors || []).sort_by { |m| m.location }.each do |m|
  35. country = m.location.match(/,/) ? m.location.split(',').last.strip : m.location
  36. countries << country unless countries.include?(country)
  37. end
  38. countries.sort
  39. end
  40. def fdo_mirror_countries
  41. mirror_countries data.mirrors.fdo
  42. end
  43. def wdo_mirror_countries
  44. mirror_countries data.mirrors.wdo
  45. end
  46. def national_mirrors(mirrors, country, partial = :mirror_fdo)
  47. national_mirrors = ""
  48. mirrors.each do |m|
  49. next unless m.location =~ /#{country}/
  50. national_mirrors << partial(partial, :locals => { m: m })
  51. end
  52. national_mirrors
  53. end
  54. def bitcoin_address
  55. "1QFbx3bKA8LABAGEaSe7EiP9JCxe2j4fN7".freeze
  56. end
  57. def breadcrumbs
  58. crumbs = current_page.path.split('/')
  59. last = crumbs.pop.sub!(/(index)?\.html$/, '').to_s # Remove HTML file
  60. path = ''
  61. crumbs.map! do |c|
  62. path << "/#{c}"
  63. link_to(c, path)
  64. end
  65. path = '<nav id="breadcrumbs">/' << crumbs.join('/')
  66. path << "/<strong>#{last}</strong>" unless last.empty?
  67. path << ' <span>' << current_page.data.title.to_s << '</span>'
  68. path << '</nav>'
  69. end
  70. def current_title
  71. current_title = "#{current_page.data.title}"
  72. current_title << ' | ' unless current_title.empty?
  73. current_title << site_title
  74. end
  75. def favicon_url
  76. "/ui/img/favicon.ico".freeze
  77. end
  78. def gitlab_new_issue(project, query)
  79. URI("https://git.devuan.org/#{project}/issues/new?#{query}").to_s
  80. end
  81. def icon(name)
  82. '<span class="icon icon-' << name << '"></span>'
  83. end
  84. def link_to_maintainer(package)
  85. mm = package.maintainer.split(',').map(&:strip)
  86. mm.map! do |maint|
  87. if maint =~ /^(.*) <(.*)>$/
  88. name, email = $1, $2
  89. "#{name} #{email}"
  90. else
  91. maint
  92. end
  93. end.join(', ')
  94. end
  95. def pkg_id(package, extra = nil)
  96. ['pkg', package, extra].compact.join('-')
  97. end
  98. def pkg_license(package)
  99. data.legal.licenses.find(package.license) do |l|
  100. link_to l.code, l.url
  101. end || "unknown license: #{l}"
  102. end
  103. def pkg_classification(pkg)
  104. c = [pkg.origin, pkg.section, pkg.priority, (t(:essential) if pkg.essential == 'yes')]
  105. content_tag('p', c.compact.join(' : '), class: 'classification')
  106. end
  107. def site_title
  108. I18n.t(:site_title)
  109. end
  110. def tagline
  111. I18n.t(:tagline)
  112. end
  113. def r(source) # render Markdown
  114. Tilt['markdown'].new { source }.render
  115. end
  116. def toc
  117. file = Pathname(File.expand_path("source/pages/" << current_page.path.chomp('.html'))).to_s
  118. file = file << ".en.html.md"
  119. unless File.exists?(file)
  120. file = file << ".erb"
  121. end
  122. return "" unless File.exists?(file)
  123. lines = File.readlines(file).select { |l| l =~ /^## / }
  124. lines.map! do |l|
  125. l.strip
  126. .sub(/^## /, '')
  127. .gsub!(/^(.*)$/) { |x| "- [#{x}](##{x.downcase.gsub(/ /, '-')})" }
  128. end
  129. lines.unshift('### Sections [ ^ ](#top)')
  130. lst = r(lines.join("\n"))
  131. toc = content_tag('nav', lst, class: 'toc')
  132. end
  133. def video_tag(url, title = nil)
  134. html = '<video src="%s" controls></video>' % url
  135. html << '<caption>%s</caption>' % title unless title.nil?
  136. '<figure>' << html << '</figure>'
  137. end
  138. end