Skip to content

Commit 6079ab5

Browse files
authored
Merge pull request #12 from alexcu/develop
Refactor Middleman Blogging for making guides
2 parents db67e6a + 339b759 commit 6079ab5

File tree

78 files changed

+962
-608
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+962
-608
lines changed

Gemfile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,26 @@ gem 'require_all', '1.3.3'
2020
gem 'middleman-autoprefixer', '~>2.7.0'
2121

2222
# Use sprokets for assets + compass
23-
gem 'middleman-sprockets', '4.0.0'
2423
gem 'middleman-compass', '4.0.1'
24+
gem 'middleman-sprockets', '4.0.0'
25+
26+
# Generating articles
27+
gem 'middleman-blog', '~> 4.0'
2528

2629
# Boostrap as SASS
27-
gem 'sass', '3.4.19'
2830
gem 'bootstrap', '~> 4.0.0.alpha4'
2931
gem 'rails-assets-tether', '>= 1.1.0'
32+
gem 'sass', '3.4.19'
3033

3134
# Grab jQuery
3235
gem 'jquery-middleman', '3.1.2'
3336

3437
# Markdown redcarpet parsing engine + syntax highlighter for middleman
35-
gem 'redcarpet', '3.3.3'
3638
gem 'middleman-syntax', '~>3.0.0'
39+
gem 'redcarpet', '3.3.3'
3740

3841
# Publish middleman website to gh-pages
3942
gem 'middleman-gh-pages', '~>0.3.0'
4043

4144
# Rake tasks
4245
gem 'rake', '10.5.0'
43-
44-
# Nokogiri for parsing HTML tags
45-
gem 'nokogiri'

Gemfile.lock

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ GEM
7070
middleman-autoprefixer (2.7.0)
7171
autoprefixer-rails (>= 6.3.1, < 7.0.0)
7272
middleman-core (>= 3.3.3)
73+
middleman-blog (4.0.2)
74+
addressable (~> 2.3)
75+
middleman-core (~> 4.0)
76+
tzinfo (>= 0.3.0)
7377
middleman-cli (4.1.10)
7478
thor (>= 0.17.0, < 2.0)
7579
middleman-compass (4.0.1)
@@ -110,11 +114,8 @@ GEM
110114
middleman-syntax (3.0.0)
111115
middleman-core (>= 3.2)
112116
rouge (~> 2.0)
113-
mini_portile2 (2.2.0)
114117
minitest (5.9.0)
115118
multi_json (1.12.1)
116-
nokogiri (1.8.0)
117-
mini_portile2 (~> 2.2.0)
118119
padrino-helpers (0.13.2)
119120
i18n (~> 0.6, >= 0.6.7)
120121
padrino-support (= 0.13.2)
@@ -154,12 +155,12 @@ DEPENDENCIES
154155
jquery-middleman (= 3.1.2)
155156
middleman (~> 4.1.0)
156157
middleman-autoprefixer (~> 2.7.0)
158+
middleman-blog (~> 4.0)
157159
middleman-compass (= 4.0.1)
158160
middleman-gh-pages (~> 0.3.0)
159161
middleman-livereload (~> 3.4.0)
160162
middleman-sprockets (= 4.0.0)
161163
middleman-syntax (~> 3.0.0)
162-
nokogiri
163164
rails-assets-tether (>= 1.1.0)
164165
rake (= 10.5.0)
165166
redcarpet (= 3.3.3)

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ $ bundle exec middleman
4040

4141
Your website will be watched and hosted locally at **[http://localhost:4567/](http://localhost:4567/)**.
4242

43+
## Bootstrap
44+
45+
We currently rely on a [Ruby Bootstrap gem](https://github.com/twbs/bootstrap-rubygem/tree/v4.0.0.alpha4) compiled with Bootstrap 4.0.0-alpha4.
46+
Relevant SASS files can be found [here](https://github.com/twbs/bootstrap-rubygem/tree/v4.0.0.alpha4/assets/stylesheets).
47+
4348
## Publishing
4449

4550
Publish using:

config.rb

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@
1414
# Automatic image dimensions on image_tag helper
1515
activate :automatic_image_sizes
1616

17+
# Activate 'blogging' to generate guides
18+
activate :blog do |guide|
19+
guide.prefix = 'articles/guides'
20+
guide.default_extension = '.md'
21+
guide.permalink = 'tags/{tags}/{title}.html'
22+
guide.layout = :'articles/guides'
23+
guide.tag_template = "#{guide.prefix}/tag_template.html"
24+
end
25+
1726
# Reload the browser automatically whenever files change
1827
configure :development do
1928
activate :livereload
@@ -22,11 +31,11 @@
2231
# Methods defined in the helpers block are available in templates
2332
helpers do
2433
# Require all functions in the helpers directory
25-
require_all 'helpers'
34+
require_all 'lib/helpers'
2635
end
2736

28-
# Helpers for string
29-
require 'lib/core_ext/string'
37+
# All overrides for core extensions
38+
require_all 'lib/core_ext'
3039

3140
# Activate sprokets + compass
3241
activate :sprockets
@@ -41,6 +50,9 @@
4150
# Set the image directory to be ./images
4251
set :images_dir, 'images'
4352

53+
# Partials must be from partials directory
54+
set :partials_dir, 'partials'
55+
4456
# Activate markdown using Redcarpet parsing engine and syntax highlighting
4557
set :markdown_engine, :redcarpet
4658
set :markdown, fenced_code_blocks: true, smartypants: true
@@ -65,28 +77,28 @@
6577
# Page options, layouts, aliases and proxies
6678
###
6779

68-
# Root Layout
80+
# Specify the root layout to index
6981
page '/index.html', layout: :index
70-
# Article layout
71-
page '/articles/*', layout: :'articles/index'
72-
73-
# Specific code guide layout
74-
page '/guides/code-examples/**/*.html', layout: :'articles/code-guide'
7582

76-
# Guides layout (use article)
77-
page '/guides/*', layout: :'articles/index'
83+
# Specify layouts for subdirectories of articles _in order_ of application
84+
page '/articles/installation/**/step*', layout: :'articles/installation'
85+
page '/articles/installation/*', layout: :'articles/index'
86+
page '/articles/guides/index.html', layout: :'articles/index'
87+
page '/articles/guides/tags/*', layout: :'articles/guides'
88+
page '/articles/guides/tags/**/*', layout: :'articles/guides'
89+
page '/articles/contributing/*', layout: :'articles/index'
90+
page '/articles/index.html', layout: :'articles/index'
7891

7992
# API proxy pages
8093
data.api.each do |api_group, data|
8194
name = api_group.to_human_case
82-
guides = find_guides_in_category('code-examples/' << name.downcase)
8395
types = (data.typedefs + data.structs + data.enums).sort_by { |h| h[:name] }
8496
locals = {
8597
raw_api_data: data,
98+
api_group: api_group,
8699
name: name,
87100
types: types,
88101
functions: data.functions,
89-
guides: guides,
90102
defines: data.defines,
91103
description: data.description,
92104
brief: data.brief

helpers/guides.rb

Lines changed: 0 additions & 49 deletions
This file was deleted.

lib/core_ext/string.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'helpers/slug'
1+
require 'lib/helpers/slug'
22

33
HUMANIZED_STRINGS = YAML.load_file('data/humanize.yml').freeze
44

@@ -13,6 +13,10 @@ def to_human_case
1313
selff.tr('_', ' ')
1414
end
1515

16+
def to_title_case
17+
split(/[_\s]/).map(&:capitalize).join(' ')
18+
end
19+
1620
def to_kebab_case
1721
to_human_case.downcase.tr(' ', '-')
1822
end

lib/helpers/guides_for_function.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Returns all blog guides that are relevant for this function.
2+
# Essentially a lookup to which guides apply to the API group that
3+
# owns the function.
4+
def guides_for_function(guides, function)
5+
guides.select do |guide|
6+
guide.metadata[:page][:related_funcs].include?(function.name)
7+
end
8+
end
9+
10+
def guides_for_api_group(api_name)
11+
blog.tags.map do |tag_name, tag_data|
12+
tag_data if tag_name == api_name
13+
end.flatten.compact
14+
end
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def sitemap_page_title
1313
# (i.e. getting started/foo/index.html -> getting started - foo)
1414
dest_path = dest_path.split('/')[0...-1].join(' - ')
1515
# Capitalize every word
16-
page_title = dest_path.split.map { |s| s.to_human_case }.join(' ')
16+
page_title = dest_path.split.map(&:to_human_case).join(' ')
1717
# Return nil if no page title, or the page_title
1818
!page_title.strip.empty? ? page_title : nil
1919
end

0 commit comments

Comments
 (0)