Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
27 changes: 27 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
AllCops:
TargetRubyVersion: 2.4
Exclude:
- '**/bin/**/*'
- '**/db/**/*'
- '**/script/setup'
- '**/vendor/**/*'

Lint/AssignmentInCondition:
Enabled: false

Metrics/BlockLength:
Enabled: false

Metrics/LineLength:
Max: 100
IgnoredPatterns: ['\A\s*#']

Style/FrozenStringLiteralComment:
Enabled: false

Style/StringLiterals:
EnforcedStyle: double_quotes

Style/TrailingCommaInLiteral:
EnforcedStyleForMultiline: consistent_comma

1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.4.1
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
language: ruby
cache: bundler
sudo: false
bundler_args: --jobs=3 --retry=3
before_install: ./script/setup
script: ./script/cibuild
6 changes: 6 additions & 0 deletions Brewfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
tap "github/bootstrap"

brew "rbenv"
brew "ruby-build"

brew "imagemagick"
8 changes: 8 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
source "https://rubygems.org"

group :test do
gem "minitest", "~> 5.10.3"
gem "rake"
gem "rubocop", "~> 0.50.0"
gem "safe_yaml", "~> 1.0.4"
end
34 changes: 34 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
GEM
remote: https://rubygems.org/
specs:
ast (2.3.0)
minitest (5.10.3)
parallel (1.12.0)
parser (2.4.0.0)
ast (~> 2.2)
powerpack (0.1.1)
rainbow (2.2.2)
rake
rake (12.0.0)
rubocop (0.50.0)
parallel (~> 1.10)
parser (>= 2.3.3.1, < 3.0)
powerpack (~> 0.1)
rainbow (>= 2.2.2, < 3.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
ruby-progressbar (1.9.0)
safe_yaml (1.0.4)
unicode-display_width (1.3.0)

PLATFORMS
ruby

DEPENDENCIES
minitest (~> 5.10.3)
rake
rubocop (~> 0.50.0)
safe_yaml (~> 1.0.4)

BUNDLED WITH
1.15.3
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
# explore
Curated topics and collections from the community

## How to Run Tests

There are some lint tests in place to ensure each topic is formatted in the way we expect. You can
run the tests using:

```bash
./script/cibuild
```
10 changes: 10 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require "rake/testtask"

Rake::TestTask.new do |t|
t.libs << "test"
t.test_files = FileList["test/*_test.rb"]
t.warning = false
t.verbose = false
end

task default: :test
14 changes: 14 additions & 0 deletions script/cibuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
set -e

cd "$(dirname "$0")/.."

./script/setup

set +e

bundle exec rake test
RAKE_EXIT="$?"
bundle exec rubocop --display-cop-names
RUBOCOP_EXIT="$?"
[[ "$RAKE_EXIT" == 0 && "$RUBOCOP_EXIT" == 0 ]]
11 changes: 11 additions & 0 deletions script/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
set -e

cd "$(dirname "$0")/.."

if [ "$(uname -s)" = "Darwin" ]; then
brew bundle check &>/dev/null || brew bundle
rbenv version-name &>/dev/null || brew bootstrap-rbenv-ruby
fi

bundle check &>/dev/null || bundle install
57 changes: 57 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
require "minitest/autorun"
require "yaml"

IMAGE_EXTENSIONS = %w[.jpg .jpeg .png].freeze

VALID_METADATA_KEYS = %w[aliases created_by display_name github_url logo related
released short_description topic url wikipedia_url].freeze

REQUIRED_METADATA_KEYS = %w[topic short_description].freeze

def topics_dir
File.expand_path("../topics", File.dirname(__FILE__))
end

def topic_dirs
Dir["#{topics_dir}/*"].select do |entry|
entry != "." && entry != ".." && File.directory?(entry)
end
end

def topics
topic_dirs.map { |dir_path| File.basename(dir_path) }
end

def image_paths_for(topic)
Dir["#{topics_dir}/#{topic}/*"].select do |entry|
File.file?(entry) && IMAGE_EXTENSIONS.include?(File.extname(entry).downcase)
end
end

def possible_image_file_names_for(topic)
IMAGE_EXTENSIONS.map { |ext| "#{topic}#{ext}" }
end

def metadata_for(topic)
path = File.join(topics_dir, topic, "index.md")
return unless File.file?(path)

parts = File.read(path).split("---", 3)
return unless parts.size >= 2

begin
YAML.safe_load(parts[1])
rescue Psych::SyntaxError => ex
flunk "invalid YAML: #{ex.message}"
end
end

def body_for(topic)
path = File.join(topics_dir, topic, "index.md")
return "" unless File.file?(path)

parts = File.read(path).split("---", 3)
return "" unless parts.size >= 2

parts[2]
end
122 changes: 122 additions & 0 deletions test/topics_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
require_relative "./test_helper"

describe "topics" do
topics.each do |topic|
describe "#{topic} topic" do
it "has an index.md" do
path = File.join(topics_dir, topic, "index.md")

assert File.file?(path), "expected #{path} to be a file"
end

it "has only one image with the right name" do
paths = image_paths_for(topic)

assert paths.size <= 1, "expected at most one image, found #{paths.size}"

if path = paths.first
assert_equal topic, File.basename(path, File.extname(path)),
"expected image to be named [topic].[extension]"
end
end

it "has no unexpected files or directories" do
files = Dir["#{topics_dir}/#{topic}/**/*"].reject do |entry|
file_name = File.basename(entry)
image_files = possible_image_file_names_for(topic)

entry == "." || entry == ".." || file_name == "index.md" ||
image_files.include?(file_name)
end

assert_empty files, "expected only index.md and a single image"
end

it "has Jekyll front matter in index.md" do
path = File.join(topics_dir, topic, "index.md")

if File.file?(path)
lines = File.readlines(path)

refute lines.empty?
assert_equal "---\n", lines[0], "expected file to start with Jekyll front matter ---"

end_index = lines.slice(1..-1).index("---\n")
assert end_index, "expected Jekyll front matter to end with ---"
end
end

it "has expected metadata in Jekyll front matter" do
metadata = metadata_for(topic)
refute_empty metadata, "expected some metadata for topic"

metadata.each_key do |key|
assert_includes VALID_METADATA_KEYS, key, "unexpected metadata key '#{key}'"
end

REQUIRED_METADATA_KEYS.each do |key|
assert metadata.key?(key), "expected to have '#{key}' defined for topic"
assert metadata[key]&.strip&.size&.positive?,
"expected to have a value for '#{key}'"
end
end

it "follows the Topic Page Style Guide" do
text = body_for(topic)
end_punctuation = %w[. , ; :] + [" "]
month_abbreviations = %w[Jan Feb Mar Apr Jun Jul Aug Sep Oct Nov Dec]
day_ordinals = %w[1st 2nd 3rd 1th 2th 3th 4th 5th 6th 7th 8th 9th]
git_verbs = %w[GitHubbing Gitting]
bad_github_variants = %w[Github github]
numbers_to_be_spelled_out = 1..9

text.lines do |line|
line.chomp!

refute_includes line, "&", 'Use "and" rather than an ampersand'
refute_includes line, "!", "Avoid exclamation points in topic pages"
refute_includes line, "open-source", "Use open source without a hyphen"

month_abbreviations.each do |month|
refute_includes line, "#{month} ", "Include and spell out the month"
end

day_ordinals.each do |date_end|
refute_includes line, date_end,
'Include the day number without the "th" or "nd" at the end'
end

git_verbs.each do |no_git_verb|
refute_includes line, no_git_verb,
"Never use “GitHub” or “Git” as a verb."
end

bad_github_variants.each do |wrong_github|
refute_includes line, wrong_github,
'Always use correct capitalization when referring to "GitHub"'
end

end_punctuation.each do |punctuation|
refute_includes line, "git#{punctuation}",
'Always use correct capitalization when referring to "Git"'

numbers_to_be_spelled_out.each do |digit|
refute_includes line, " #{digit}#{punctuation}",
'Write out "one" and every number less than 10'
end
end
end

text.delete("\n").split(".").each do |sentence|
# This is arbitrary; 2 is more correct but 3 avoids false positives.
next if sentence.count(",") < 3

%w[and or].each do |conjunction|
next unless sentence.include? " #{conjunction} "
assert_includes sentence, ", #{conjunction}", "Always use the Oxford comma"
end
end
end
end
end
end
2 changes: 1 addition & 1 deletion topics/3d/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ short_description: 3D modeling is the process of virtually developing the surfac
topic: 3d
wikipedia_url: https://en.wikipedia.org/wiki/3D_modeling
---
3D modeling uses specialized software to create a digital model of a physical object. It is an aspect of 3D computer graphics, used for video games, 3D printing and VR, among other applications.
3D modeling uses specialized software to create a digital model of a physical object. It is an aspect of 3D computer graphics, used for video games, 3D printing, and VR, among other applications.
2 changes: 1 addition & 1 deletion topics/csharp/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ topic: csharp
url: https://docs.microsoft.com/en-us/dotnet/csharp/csharp
wikipedia_url: https://en.wikipedia.org/wiki/C_Sharp_(programming_language)
---
C# is a programming language used for web development. It is a hybrid of C & C++ that functions similar to Java and is meant for Microsoft's .NET framework.
C# is a programming language used for web development. It is a hybrid of C and C++ that functions similar to Java and is meant for Microsoft's .NET framework.
2 changes: 1 addition & 1 deletion topics/database/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ short_description: A database is a structured set of data held in a computer, us
topic: database
wikipedia_url: https://en.wikipedia.org/wiki/Database
---
A database is a structured set of data held in a computer, most often a server. Databases use a database management system (DBMS) that interacts with users, similar to a lookup table. Modern databases are designed to allow for creation, querying, updating and administration of the data it holds.
A database is a structured set of data held in a computer, most often a server. Databases use a database management system (DBMS) that interacts with users, similar to a lookup table. Modern databases are designed to allow for creation, querying, updating, and administration of the data it holds.
2 changes: 1 addition & 1 deletion topics/gulp/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ topic: gulp
url: http://gulpjs.com/
wikipedia_url: https://en.wikipedia.org/wiki/Gulp.js
---
Gulp is an open source toolkit built on Node.js & npm. It is used for automating and streamlining repetitive tasks in front-end web development.
Gulp is an open source toolkit built on Node.js and npm. It is used for automating and streamlining repetitive tasks in front-end web development.
2 changes: 1 addition & 1 deletion topics/ios/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ topic: ios
url: https://www.apple.com/ios/
wikipedia_url: https://en.wikipedia.org/wiki/IOS
---
iOS is the operating system for all of Apple’s mobile products. The operating system was unveiled at Macworld Conference & Expo in 2007 to support the company’s new venture, the iPhone. Since then, the operating system has grown to incorporate other products, including the iPad and iPod Touch.
iOS is the operating system for all of Apple’s mobile products. The operating system was unveiled at Macworld Conference and Expo in 2007 to support the company’s new venture, the iPhone. Since then, the operating system has grown to incorporate other products, including the iPad and iPod Touch.
2 changes: 1 addition & 1 deletion topics/mysql/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ topic: mysql
url: https://www.mysql.com/
wikipedia_url: https://en.wikipedia.org/wiki/MySQL
---
MySQL is an open source relational database management system. Based in Structured Query Language (SQL), MySQL can run on most platforms and is mainly used for web-based applications. It is written in C & C++.
MySQL is an open source relational database management system. Based in Structured Query Language (SQL), MySQL can run on most platforms and is mainly used for web-based applications. It is written in C and C++.
2 changes: 1 addition & 1 deletion topics/react-native/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ topic: react-native
url: http://reactnative.com/
wikipedia_url: https://en.wikipedia.org/wiki/React_(JavaScript_library)#React_Native
---
React Native is a JavaScript mobile framework developed by Facebook. It allows developers to build Android & iOS mobile apps using JavaScript and reuse code across web & mobile applications.
React Native is a JavaScript mobile framework developed by Facebook. It allows developers to build Android and iOS mobile apps using JavaScript and reuse code across web and mobile applications.
2 changes: 1 addition & 1 deletion topics/redux/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ topic: redux
url: http://redux.js.org/
wikipedia_url: https://en.wikipedia.org/wiki/Redux_(JavaScript_library)
---
Redux is an open-source JavaScript library, designed to allow for state management of JavaScript applications. Inspired by Elm, Redux is a debugging tool and supports robust application data-flow architecture. Redux is frequently used in combination with React.
Redux is an open source JavaScript library, designed to allow for state management of JavaScript applications. Inspired by Elm, Redux is a debugging tool and supports robust application data-flow architecture. Redux is frequently used in combination with React.