mirror of https://github.com/freeCodeCamp/devdocs
Made LÖVE scraper and filters work semi-properly
Added LÖVE icons
Added syntax highlighting to LÖVE documentation
LÖVE: Style hints and tables
LÖVE: Added stylesheet
LÖVE: Exclude 'PO2 Syndrome' and remove 'Config Files' from initial paths
LÖVE: Sanitize file names
LÖVE: Refactored style filters and added version-dependent-feature boxes
LÖVE: Added style for hr elements, fixed style for h3 elements; Replaced JS with SimplePage; Sorted CSS into list correctly
LÖVE: Add types to all pages as required since 5bb96f804a
LÖVE: Remove unnescessary linebreak after notice blocks
LÖVE: Categorized/removed certain remaining pages and made sure that all modules are being scraped even if they aren't referenced
LÖVE: Minor fixes
LÖVE: Fixed two bugs
pull/427/head
parent
19d811b0f4
commit
a25290de80
@ -0,0 +1,67 @@
|
||||
._love {
|
||||
padding-left: 1rem;
|
||||
|
||||
h1, h2 { margin-left: -1rem; }
|
||||
h2 { @extend %block-heading; }
|
||||
h3 { margin-left: -0.5rem; @extend %block-label; }
|
||||
|
||||
._mobile & {
|
||||
padding-left: 0;
|
||||
|
||||
h1, h2, h3 { margin-left: 0; }
|
||||
}
|
||||
|
||||
p > code, li > code { @extend %label; }
|
||||
blockquote { @extend %note; }
|
||||
|
||||
.box { @extend %box; }
|
||||
.note { @extend %note; }
|
||||
.label { @extend %label; }
|
||||
|
||||
.box-heading {
|
||||
@extend %heading-box;
|
||||
padding: .5em .75em;
|
||||
margin-top: 1.5rem;
|
||||
margin-bottom: 0px;
|
||||
border-bottom: none;
|
||||
border-bottom-left-radius: 0px;
|
||||
border-bottom-right-radius: 0px;
|
||||
}
|
||||
.box-with-heading {
|
||||
@extend %box;
|
||||
padding: .5em .75em;
|
||||
margin-top: 0px;
|
||||
margin-bottom: 1.5rem;
|
||||
border-top-left-radius: 0px;
|
||||
border-top-right-radius: 0px;
|
||||
}
|
||||
|
||||
.note-green, .label-green { @extend %note-green; }
|
||||
.note-red, .label-red { @extend %note-red; }
|
||||
.note-orange, .label-orange { @extend %note-orange; }
|
||||
.cell-green { background: $noteGreenBackground; }
|
||||
.cell-red { background: $noteRedBackground; }
|
||||
|
||||
.smwtable {
|
||||
width: 100%;
|
||||
tr {
|
||||
td {
|
||||
word-wrap: break-word;
|
||||
}
|
||||
|
||||
td:first-child, td:nth-last-child(2), td:last-child {
|
||||
vertical-align: middle;
|
||||
white-space: nowrap;
|
||||
width: 1em;
|
||||
overflow: hidden;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
hr {
|
||||
border: none;
|
||||
height: 1px;
|
||||
background-color: $textColorLighter;
|
||||
margin: 1.5em 0 1em;
|
||||
}
|
||||
}
|
@ -0,0 +1,103 @@
|
||||
module Docs
|
||||
class Love
|
||||
class CleanHtmlFilter < Filter
|
||||
def call
|
||||
# Fix syntax highlighting
|
||||
css('.mw-code').each do |node|
|
||||
node.content = node.at_css("div > pre").content
|
||||
node['data-language'] = 'lua'
|
||||
node.name = 'pre'
|
||||
end
|
||||
|
||||
# Move header tags up
|
||||
css('h2', 'h3').each do |node|
|
||||
headline = node.at_css('.mw-headline')
|
||||
node['id'] = headline['id']
|
||||
node.content = headline.inner_text
|
||||
end
|
||||
|
||||
# Move dt tags up
|
||||
css('dt > span').each do |node|
|
||||
node.parent.content = node.inner_text
|
||||
end
|
||||
|
||||
# Style notices and new/removed sections
|
||||
css('.notice', '.new-section', '.removed-section', '.removed-new-section').each do |node|
|
||||
case node['class']
|
||||
when 'notice'
|
||||
node['class'] = 'note note-warning'
|
||||
node.inner_html = node.at_css('td:nth-child(2)').inner_html
|
||||
node.next.remove unless node.next.nil? or node.next.name != 'br'
|
||||
when 'new-section', 'removed-section', 'removed-new-section'
|
||||
node['class'] = node['class'] == 'new-section' ? 'note note-green' : 'note note-red'
|
||||
node.inner_html = node.at_css('tr > td > i').inner_html \
|
||||
+ '<br>' \
|
||||
+ node.at_css('tr > td > small').inner_html
|
||||
end
|
||||
|
||||
node.name = 'p'
|
||||
node.remove_attribute('bgcolor')
|
||||
node.remove_attribute('style')
|
||||
node.remove_attribute('align')
|
||||
end
|
||||
|
||||
# Style new/removed features
|
||||
css('.new-feature', '.removed-feature', '.removed-new-feature').each do |node|
|
||||
node.name = 'div'
|
||||
node['class'] = node['class'] == 'new-feature' ? 'box-heading label-green' : 'box-heading label-red'
|
||||
node.remove_attribute('style')
|
||||
|
||||
container = node.next_element
|
||||
container.name = 'div'
|
||||
container['class'] = 'box-with-heading'
|
||||
container.remove_attribute('style')
|
||||
end
|
||||
|
||||
# Style tables
|
||||
css('table.smwtable').each do |table|
|
||||
table.remove_attribute('style')
|
||||
table.css('td').each do |cell|
|
||||
cell.remove_attribute('style')
|
||||
end
|
||||
table.css('td:last-child', 'td:nth-last-child(2)').each do |cell|
|
||||
img = cell.at_css('img')
|
||||
if img then
|
||||
if img['alt'] == 'Added since' then
|
||||
cell['class'] = 'cell-green'
|
||||
elsif img['alt'] == 'Removed in'
|
||||
cell['class'] = 'cell-red'
|
||||
end
|
||||
img.remove
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Remove Other Languages
|
||||
css('#Other_Languages').remove
|
||||
css('.i18n').remove
|
||||
|
||||
# Remove changelog
|
||||
node = at_css('h2#Changelog')
|
||||
if !node.nil? then
|
||||
begin
|
||||
nxt = node.next
|
||||
node.remove
|
||||
node = nxt
|
||||
end while !node.nil? and node.name != 'h2'
|
||||
end
|
||||
|
||||
# Remove empty paragraphs
|
||||
css('p').each do |node|
|
||||
node.remove if node.inner_text.strip == ''
|
||||
end
|
||||
|
||||
# Remove linebreaks that are the first or last child of a paragraph
|
||||
css('p > br:first-child', 'p > br:last-child').each do |node|
|
||||
node.remove
|
||||
end
|
||||
|
||||
doc
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,22 @@
|
||||
module Docs
|
||||
class Love
|
||||
class EntriesFilter < Docs::EntriesFilter
|
||||
def get_type
|
||||
if TYPE_OVERRIDE.key?(slug) then
|
||||
return TYPE_OVERRIDE[slug]
|
||||
elsif m = slug.match(/\A(love\.\w+)\z/) then
|
||||
# modules and funcions
|
||||
return LOVE_MODULES.include?(m[1]) ? m[1] : 'love'
|
||||
elsif m = slug.match(/\A(love\.\w+)\.(\w+)/) then
|
||||
# functions in modules
|
||||
return m[1]
|
||||
elsif context[:list_classes] and (m = slug.match(/\A\(?([A-Z]\w+)\)?(\:\w+)?/)) then
|
||||
# classes, their members and enums
|
||||
return m[1] unless m[1].include?('_')
|
||||
end
|
||||
# usually this shouldn't happen
|
||||
"Other"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,99 @@
|
||||
module Docs
|
||||
class Love < UrlScraper
|
||||
LOVE_MODULES = %w(
|
||||
love
|
||||
love.audio
|
||||
love.event
|
||||
love.filesystem
|
||||
love.font
|
||||
love.graphics
|
||||
love.image
|
||||
love.joystick
|
||||
love.keyboard
|
||||
love.math
|
||||
love.mouse
|
||||
love.physics
|
||||
love.sound
|
||||
love.system
|
||||
love.thread
|
||||
love.timer
|
||||
love.touch
|
||||
love.video
|
||||
love.window
|
||||
)
|
||||
TYPE_OVERRIDE = {
|
||||
"Audio_Formats" => "love.sound",
|
||||
"ImageFontFormat" => "love.font",
|
||||
"BlendMode_Formulas" => "BlendMode",
|
||||
"Shader_Variables" => "Shader"
|
||||
}
|
||||
|
||||
self.name = 'LÖVE'
|
||||
self.slug = 'love'
|
||||
self.type = 'love'
|
||||
self.base_url = 'https://love2d.org/wiki/'
|
||||
self.root_path = 'love'
|
||||
self.initial_paths = LOVE_MODULES
|
||||
self.links = {
|
||||
home: 'https://love2d.org/',
|
||||
code: 'https://bitbucket.org/rude/love'
|
||||
}
|
||||
|
||||
html_filters.push 'love/clean_html', 'love/entries', 'title'
|
||||
|
||||
options[:root_title] = 'love'
|
||||
options[:initial_paths] = LOVE_MODULES
|
||||
|
||||
options[:decode_and_clean_paths] = true
|
||||
|
||||
# Add types to classes and their members
|
||||
options[:list_classes] = true
|
||||
|
||||
options[:container] = '#mw-content-text'
|
||||
|
||||
options[:only_patterns] = [
|
||||
/\A(love\z|love\.|[A-Z]|\([A-Z])/
|
||||
# love
|
||||
# love.* (modules and functions)
|
||||
# Uppercased (classes and enums)
|
||||
# (Uppercased) (generalized classes)
|
||||
]
|
||||
options[:skip] = %w(
|
||||
Getting_Started
|
||||
Building_LÖVE
|
||||
Tutorial
|
||||
Tutorials
|
||||
Game_Distribution
|
||||
License
|
||||
Games
|
||||
Libraries
|
||||
Software
|
||||
Snippets
|
||||
Version_History
|
||||
Lovers
|
||||
PO2_Syndrome
|
||||
HSL_color
|
||||
)
|
||||
options[:skip_patterns] = [
|
||||
/_\([^\)]+\)\z/,
|
||||
# anything_(language) (this might have to be tweaked)
|
||||
/\ASpecial:/,
|
||||
/\ACategory:/,
|
||||
/\AFile:/,
|
||||
/\AHelp:/,
|
||||
/\ATemplate:/,
|
||||
/\AUser:/,
|
||||
/\ATutorial:/
|
||||
# special pages are indistinguishable from instance methods
|
||||
]
|
||||
|
||||
options[:replace_paths] = {
|
||||
"Config_Files" => "love.conf"
|
||||
}
|
||||
|
||||
options[:attribution] = <<-HTML
|
||||
© LÖVE Development Team<br>
|
||||
Licensed under the GNU Free Documentation License, Version 1.3.
|
||||
HTML
|
||||
end
|
||||
end
|
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 2.6 KiB |
@ -0,0 +1 @@
|
||||
https://bytebucket.org/rude/love/raw/default/platform/unix/love.svg
|
Loading…
Reference in new issue