Import the pebble dev site into devsite/

This commit is contained in:
Katharine Berry 2025-02-17 17:02:33 -08:00
parent 3b92768480
commit 527858cf4c
1359 changed files with 265431 additions and 0 deletions

73
devsite/spec/docs.rb Normal file
View file

@ -0,0 +1,73 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
require 'open-uri'
require 'jekyll'
shared_context 'docs' do
def load_config
config = File.join(File.dirname(__FILE__), '../source/_data/docs.yaml')
YAML.load(File.read(config))
end
def valid_branch(branch)
expect(branch[:name]).to respond_to(:to_s)
expect(branch[:url]).to respond_to(:to_s)
expect(branch[:children]).to respond_to(:to_a)
branch[:children].to_a.each { |child| valid_branch(child) }
end
def valid_branch2(branch)
expect(branch[:name]).to respond_to(:to_s)
expect(branch[:url]).to respond_to(:to_s)
expect(branch[:children]).to respond_to(:to_a)
branch[:children].to_a.each { |child| valid_branch2(child) }
end
# rubocop:disable Metrics/MethodLength
def fake_site
config = Jekyll::Configuration::DEFAULTS
config['source'] = './source/'
Jekyll::Site.new(config)
end
# rubocop:enable Metrics/MethodLength
# Iterate through all of the symbols and make sure that there is no other
# symbol with the same name.
def clashing_symbols(symbols)
symbols.any? do |symbol|
symbols.any? do |sym|
return false if sym == symbol
return true if sym[:name] == symbol[:name] || sym[:url] == symbol[:url]
false
end
end
end
# Iterate through all of symbols and make sure that we have a matching
# page that the symbol is linking to.
def symbol_to_page_completeness(symbols, pages)
symbols.each do |symbol|
file = symbol[:url][/^([^#]*)/].gsub('%2B', '+')
has_page = pages.any? do |page|
page.url == file || page.url == File.join(file, 'index.html') || page.url == file + '/'
end
expect(has_page).to be true
end
end
def find_symbol(symbols, name)
symbols.index { |symbol| symbol[:name] == name }
end
end

View file

@ -0,0 +1,39 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
require 'liquid'
require_relative '../plugins/filter_assetify'
describe FilterAssetify, '#assetify' do
let(:liquid) { Class.new.extend(FilterAssetify) }
before do
site = double(Class)
allow(site).to receive_messages(:config => { 'asset_path' => 'ASSET_PATH' })
context = double(Liquid::Context)
allow(context).to receive_messages(:registers => { :site => site })
liquid.instance_variable_set("@context", context)
end
it 'prepends the provided asset_path when needed' do
expect(liquid.assetify('/images/foo.png')).to eql('ASSET_PATH/images/foo.png')
end
it 'does not prepend the provided asset_path when not needed' do
expect(liquid.assetify('//images/foo.png')).to eql('//images/foo.png')
expect(liquid.assetify('images/foo.png')).to eql('images/foo.png')
end
end

7653
devsite/spec/fixtures/js.json vendored Normal file

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,115 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
require_relative './spec_helper'
require 'jekyll'
require_relative '../lib/pebble_documentation'
require_relative '../lib/pebble_documentation_pebblekit_android'
require_relative './docs'
describe Pebble::DocumentationPebbleKitAndroid do
include_context 'docs'
before do
@docs_config = load_config
@site = fake_site
allow(File).to receive(:read).and_return('')
source = ENV['DOCS_URL'] + @docs_config['pebblekit_android']
@doc = Pebble::DocumentationPebbleKitAndroid.new(@site, source)
end
describe '#load_symbols' do
before do
@symbols = []
@doc.load_symbols(@symbols)
end
it 'should add symbols to the list' do
expect(@symbols.size).to be > 0
end
it 'should contain some known symbols' do
symbols = %w(
com.getpebble.android.kit.Constants
com.getpebble.android.kit.PebbleKit.registerReceivedDataHandler
com.getpebble.android.kit.util.PebbleDictionary.remove
)
symbols.each { |name| expect(find_symbol(@symbols, name)).to_not be(nil) }
end
it 'should tag all symbols with the correct language' do
expect(@symbols.any? { |symbol| symbol[:language] != 'pebblekit_android' })
.to be(false)
end
it 'should create symbols with correct URLS' do
wrong_prefix = @symbols.any? do |symbol|
!symbol[:url].start_with?('/docs/pebblekit-android/')
end
expect(wrong_prefix).to be(false)
end
it 'should not create two symbols that clash' do
expect(clashing_symbols(@symbols)).to be false
end
end
describe '#create_pages' do
before do
@pages = []
@doc.create_pages(@pages)
end
it 'should add some pages to the list' do
expect(@pages.size).to be > 0
end
it 'should create pages with contents and group exposed' do
page = @pages[0]
expect(page.contents).to_not be(nil)
expect(page.group).to_not be(nil)
end
end
describe '#build_tree' do
before do
@tree = []
@doc.build_tree(@tree)
end
it 'should populate the tree' do
expect(@tree.size).to be > 0
end
it 'should create tree objects formatted properly' do
@tree.each { |branch| valid_branch(branch) }
end
end
describe 'completeness' do
before do
@tree = []
@symbols = []
@pages = []
@doc.build_tree(@tree)
@doc.create_pages(@pages)
@doc.load_symbols(@symbols)
end
it 'should have a page for every symbol' do
symbol_to_page_completeness(@symbols, @pages)
end
end
end

View file

@ -0,0 +1,124 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
require_relative './spec_helper'
require 'jekyll'
require_relative '../lib/pebble_documentation'
require_relative '../lib/pebble_documentation_c'
require_relative '../plugins/generator_redirects'
require_relative './docs'
describe Pebble::DocumentationC do
include_context 'docs'
before do
@docs_config = load_config
@site = fake_site
allow(File).to receive(:read) do | path |
if path.start_with?('/_layouts/')
''
else
File.open(path) do |f|
f.read
end
end
end
source = ENV['DOCS_URL'] + @docs_config['c']
@doc = Pebble::DocumentationC.new(@site, source, '/docs/c/')
end
describe '#load_symbols' do
before do
@symbols = []
@doc.load_symbols(@symbols)
end
it 'should add symbols to the list' do
expect(@symbols.size).to be > 0
end
it 'should contain some known symbols' do
symbols = %w(
Window
text_layer_create
GBitmap
GColorBlack
GBitmapSequence
)
symbols.each { |name| expect(find_symbol(@symbols, name)).to_not be(nil), "Could not find symbol #{name}" }
end
it 'should tag all symbols with the correct language' do
expect(@symbols.any? { |symbol| symbol[:language] != 'c' }).to be(false)
end
it 'should create symbols with correct URL prefix' do
wrong_prefix = @symbols.any? do |symbol|
!symbol[:url].start_with?('/docs/c/')
end
expect(wrong_prefix).to be(false)
end
it 'should not create two symbols that clash' do
expect(clashing_symbols(@symbols)).to be false
end
end
describe '#create_pages' do
before do
@pages = []
@doc.create_pages(@pages)
end
it 'should add some pages to the list' do
expect(@pages.size).to be > 0
end
it 'should create pages with the group exposed' do
page = @pages[0]
expect(page.group).to_not be(nil)
end
end
describe '#build_tree' do
before do
@tree = []
@doc.build_tree(@tree)
end
it 'should populate the tree' do
expect(@tree.size).to be > 0
end
it 'should create tree objects formatted properly' do
@tree.each { |branch| valid_branch2(branch) }
end
end
describe 'completeness' do
before do
@tree = []
@symbols = []
@pages = []
@doc.build_tree(@tree)
@doc.create_pages(@pages)
@doc.load_symbols(@symbols)
end
it 'should have a page for every symbol' do
symbol_to_page_completeness(@symbols, @pages)
end
end
end

View file

@ -0,0 +1,128 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
require_relative './spec_helper'
require 'jekyll'
require_relative '../lib/pebble_documentation'
require_relative '../lib/pebble_documentation_pebblekit_ios'
require_relative './docs'
describe Pebble::DocumentationPebbleKitIos do
include_context 'docs'
before do
@docs_config = load_config
@site = fake_site
allow(File).to receive(:read).and_return('')
source = ENV['DOCS_URL'] + @docs_config['pebblekit_ios']
@doc = Pebble::DocumentationPebbleKitIos.new(@site, source, '/docs/pebblekit-ios/')
end
describe '#load_symbols' do
before do
@symbols = []
@doc.load_symbols(@symbols)
end
it 'should add symbols to the list' do
expect(@symbols.size).to be > 0
end
it 'should contain some known symbols' do
symbols = [
'pb_pebbleDictionaryData:',
'isMobileAppInstalled',
'PBWatch',
'dataLoggingService:hasSInt8s:numberOfItems:forDataLoggingSession:'
]
symbols.each { |name| expect(find_symbol(@symbols, name)).to_not be(nil) }
end
it 'should tag all symbols with the correct language' do
expect(@symbols.any? { |symbol| symbol[:language] != 'pebblekit_ios' }).to be(false)
end
it 'should create symbols with correct URLS' do
wrong_prefix = @symbols.any? do |symbol|
!symbol[:url].start_with?('/docs/pebblekit-ios/')
end
expect(wrong_prefix).to be(false)
end
it 'should not create two symbols that clash'
it 'should trim whitespace from summary' do
not_trimmed = @symbols.any? do |symbol|
!symbol[:summary].nil? && symbol[:summary].strip != symbol[:summary]
end
expect(not_trimmed).to be(false)
end
it 'should URLencode the symbol URLS' do
bad_urls = @symbols.any? do |symbol|
symbol[:url].include?('+')
end
expect(bad_urls).to be(false)
end
end
describe '#create_pages' do
before do
@pages = []
@doc.create_pages(@pages)
end
it 'should add some pages to the list' do
expect(@pages.size).to be > 0
end
it 'should create pages with contents and group exposed' do
page = @pages[0]
expect(page.contents).to_not be(nil)
expect(page.group).to_not be(nil)
end
end
describe '#build_tree' do
before do
@tree = []
@doc.build_tree(@tree)
end
it 'should populate the tree' do
expect(@tree.size).to be > 0
end
it 'should create tree objects formatted properly' do
@tree.each { |branch| valid_branch(branch) }
end
end
describe 'completeness' do
before do
@tree = []
@symbols = []
@pages = []
@doc.build_tree(@tree)
@doc.create_pages(@pages)
@doc.load_symbols(@symbols)
end
it 'should have a page for every symbol' do
symbol_to_page_completeness(@symbols, @pages)
end
end
end

View file

@ -0,0 +1,107 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
require_relative './spec_helper'
require 'jekyll'
require_relative '../lib/pebble_documentation'
require_relative '../lib/pebble_documentation_js'
require_relative '../plugins/pebble_markdown_parser'
require_relative './docs'
describe Pebble::DocumentationJs do
include_context 'docs'
before do
@docs_config = load_config
@site = fake_site
@site.data['js'] = JSON.parse(File.read('spec/fixtures/js.json'))
@doc = Pebble::DocumentationJs.new(@site, 'js', '/docs/js/', 'js')
end
describe '#load_symbols' do
before do
@symbols = []
@doc.load_symbols(@symbols)
end
it 'should add symbols to the list' do
expect(@symbols.size).to be > 0
end
it 'should contain some known symbols' do
expect(find_symbol(@symbols, 'addEventListener')).to_not be(nil)
expect(find_symbol(@symbols, 'removeEventListener')).to_not be(nil)
end
it 'should tag all symbols with the correct language' do
expect(@symbols.any? { |symbol| symbol[:language] != 'js' }).to be(false)
end
it 'should create symbols with correct URLS' do
expect(@symbols.any? { |symbol| !symbol[:url].start_with?('/docs/js/') })
.to be(false)
end
it 'should not create two symbols that clash' do
expect(clashing_symbols(@symbols)).to be false
end
end
describe '#create_pages' do
before do
@pages = []
@doc.create_pages(@pages)
end
it 'should add some pages to the list' do
expect(@pages.size).to be > 0
end
it 'should create pages with module details exposed' do
page = @pages[0]
expect(page.js_module).to_not be(nil)
end
end
describe '#build_tree' do
before do
@tree = []
@doc.build_tree(@tree)
end
it 'should populate the tree' do
expect(@tree.size).to be > 0
end
it 'should create tree objects formatted properly' do
@tree.each { |branch| valid_branch(branch) }
end
end
describe 'completeness' do
before do
@tree = []
@symbols = []
@pages = []
@doc.build_tree(@tree)
@doc.create_pages(@pages)
@doc.load_symbols(@symbols)
end
it 'should have a page for every symbol' do
symbol_to_page_completeness(@symbols, @pages)
end
end
end

View file

@ -0,0 +1,258 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
require_relative './spec_helper'
require 'redcarpet'
require 'jekyll'
require 'nokogiri'
require_relative '../plugins/pebble_markdown_parser'
describe Jekyll::Converters::Markdown::PebbleMarkdownParser, '#convert' do
it 'renders normal markdown properly' do
expect(parser.convert('**Bold Text**').strip)
.to eql('<p><strong>Bold Text</strong></p>')
end
it 'adds anchors to headers' do
doc = md2doc("# Header 1\n## Header 2")
expect(doc.at_css('h1').attribute('id').value).to eql('header-1')
expect(doc.at_css('h1').content).to eql('Header 1')
expect(doc.at_css('h2').attribute('id').value).to eql('header-2')
expect(doc.at_css('h2').content).to eql('Header 2')
end
describe 'links' do
it 'prepends the site base URL to absolute links' do
links = [
['/link1/', '/BASEURL/link1/'],
['link2/', 'link2/'],
['//link3/', '//link3/']
]
doc = md2doc(links.map { |link| "[link](#{link[0]})" }.join('\n'))
links.each_with_index do |link, index|
expect(doc.at_css("a:nth-child(#{index + 1})").attribute('href').value)
.to eql(link[1])
end
end
describe 'buttons' do
it 'can generate a simple button' do
doc = md2doc('[button >](http://google.com)')
expect(doc.at_css('a').attribute('class').value)
.to eql('btn btn--markdown')
expect(doc.at_css('a').content).to eql('button')
end
it 'can generate a button with additional classes' do
doc = md2doc('[button >{large,pink}](http://google.com)')
expect(doc.at_css('a').attribute('class').value)
.to eql('btn btn--markdown btn--large btn--pink')
expect(doc.at_css('a').content).to eql('button')
end
end
describe 'data attributes' do
it 'can add a single data attribute to a link' do
doc = md2doc('[link](http://google.com "title >{item:foo}")')
expect(doc.at_css('a').attribute('data-item').value).to eql('foo')
expect(doc.at_css('a').attribute('title').value).to eql('title')
end
it 'can add a multiple data attributes to a link' do
doc = md2doc('[link](http://google.com "title >{item:foo,item2:bar}")')
expect(doc.at_css('a').attribute('data-item').value).to eql('foo')
expect(doc.at_css('a').attribute('data-item2').value).to eql('bar')
expect(doc.at_css('a').attribute('title').value).to eql('title')
end
it 'can add data attributes without a title' do
doc = md2doc('[link](http://google.com " >{item:foo}")')
expect(doc.at_css('a').attribute('data-item').value).to eql('foo')
expect(doc.at_css('a').attribute('title').value).to eql('')
end
end
describe 'embeds' do
it 'generates YouTube video embeds' do
id = 'dQw4w9WgXcQ'
doc = md2doc("[EMBED](https://www.youtube.com/watch?v=#{id})")
expect(doc.at_css('iframe').attribute('src').value)
.to eql("//www.youtube.com/embed/#{id}?rel=0")
doc = md2doc("[EMBED](https://www.youtube.com/v/#{id})")
expect(doc.at_css('iframe').attribute('src').value)
.to eql("//www.youtube.com/embed/#{id}?rel=0")
doc = md2doc("[EMBED](//www.youtube.com/v/#{id})")
expect(doc.at_css('iframe').attribute('src').value)
.to eql("//www.youtube.com/embed/#{id}?rel=0")
end
it 'generates YouTube playlist embeds' do
id = 'PLDPHNsf1sb4-EXiIUOGqsX81etZepB7C0'
doc = md2doc("[EMBED](https://www.youtube.com/playlist?list=#{id})")
expect(doc.at_css('iframe').attribute('src').value)
.to eql("//www.youtube.com/embed/videoseries?list=#{id}")
end
it 'generates Vimeo video embeds' do
id = '0581081381803'
doc = md2doc("[EMBED](//player.vimeo.com/video/#{id}?title=0&byline=0)")
expect(doc.at_css('iframe').attribute('src').value)
.to eql("//player.vimeo.com/video/#{id}")
end
it 'generated Gist embeds' do
id = '57a8c2b8670b9a6b7119'
doc = md2doc("[EMBED](https://gist.github.com/matthewtole/#{id})")
expect(doc.at_css('script').attribute('src').value)
.to eql("//gist.github.com/matthewtole/#{id}.js")
end
end
end
describe 'images' do
it 'prepends the asset path for absolute paths' do
images = [
['/img1.png', '//ASSETS/img1.png'],
['img2.png', 'img2.png'],
['//img3.png', '//img3.png']
]
doc = md2doc(images.map { |img| "![](#{img[0]})" }.join(' '))
images.each_with_index do |img, index|
expect(doc.at_css("img:nth-child(#{index + 1})").attribute('src').value)
.to eql(img[1])
end
end
describe 'size' do
it 'can specify the width of an image' do
doc = md2doc('![Alt Text](image_url =300)')
expect(doc.at_css('img').attribute('width').value).to eql('300')
end
it 'can specify the width and height of an image' do
doc = md2doc('![Alt Text](image_url =300x200)')
expect(doc.at_css('img').attribute('width').value).to eql('300')
expect(doc.at_css('img').attribute('height').value).to eql('200')
end
end
end
describe 'paragraphs' do
it 'adds a data attribute for sdk platforms' do
doc = md2doc("^LC^ Local SDK instructions\n\n^CP^CloudPebble instructions\n\nRegular old paragraph")
expect(doc.at_css('p:nth-child(1)').attribute('data-sdk-platform').value).to eql('local')
expect(doc.at_css('p:nth-child(1)').content).to eql('Local SDK instructions')
expect(doc.at_css('p:nth-child(1)')['class']).to include('platform-specific')
expect(doc.at_css('p:nth-child(2)').attribute('data-sdk-platform').value).to eql('cloudpebble')
expect(doc.at_css('p:nth-child(2)').content).to eql('CloudPebble instructions')
expect(doc.at_css('p:nth-child(2)')['class']).to include('platform-specific')
expect(doc.at_css('p:nth-child(3)').attribute('data-sdk-platform')).to eql(nil)
expect(doc.at_css('p:nth-child(3)').content).to eql('Regular old paragraph')
end
end
describe 'block code' do
it 'processes code blocks with Pygments' do
doc = md2doc("```\nvar a = 1;\n```")
expect(doc.at_css('div.highlight')).to_not be_nil
expect(doc.css('div.highlight span').size).to be > 0
end
it 'skips highlighting if language is text' do
doc = md2doc("```text\nvar a = 1;\n```")
expect(doc.at_css('div.highlight > pre')).to_not be_nil
expect(doc.css('div.highlight span').size).to be(0)
end
it 'adds no-copy to classes if nc prefix' do
doc = md2doc("```nc|js\nvar a = 1;\n```")
div = doc.at_css('div.highlight')
expect(div['class']).to include('no-copy')
end
end
describe 'documentation auto-linking' do
before do
allow(Jekyll.logger).to receive(:warn)
end
it 'should convert double backticks into documentation links' do
doc = md2doc("``Window``")
link = doc.at_css('a')
expect(link).to_not be_nil
expect(link.attribute('href').value).to eql('/BASEURL/docs/c/Window/')
expect(link['class']).to include('link--docs')
expect(link.at_css('code').content).to eql('Window')
end
it 'should use the language prefix where available' do
doc = md2doc("``pebblejs:Window``")
link = doc.at_css('a')
expect(link).to_not be_nil
expect(link.attribute('href').value).to eql('/BASEURL/docs/pebblejs/Window/')
expect(link['class']).to include('link--docs')
expect(link.at_css('code').content).to eql('Window')
end
it 'should print a warning if symbol not found' do
expect(Jekyll.logger).to receive(:warn).once
doc = md2doc("``pebblejs:NotASymbol``")
end
it 'should remove the prefix if symbol not found' do
doc = md2doc("``pebblejs:NotASymbol``")
code = doc.at_css('code')
expect(code.content).to eql('NotASymbol')
end
it 'should convert double backticks from inside links' do
doc = md2doc("[LinkTitle](``window``)")
link = doc.at_css('a')
expect(link).to_not be_nil
expect(link.attribute('href').value).to eql('/BASEURL/docs/c/Window/')
expect(link['class']).to include('link--docs')
expect(link.content).to eql('LinkTitle')
end
it 'should handle missing link uses' do
doc = md2doc("[LinkTitle](``DoesNotExist``)")
code = doc.at_css('p')
expect(code.content).to eql('LinkTitle')
end
end
def md2doc(markdown)
html = parser.convert(markdown)
Nokogiri::HTML.fragment(html)
end
def parser
site = {
'baseurl' => '/BASEURL',
'asset_path' => '//ASSETS',
docs: {
symbols: fake_symbols
}
}
Jekyll::Converters::Markdown::PebbleMarkdownParser.new(site)
end
def fake_symbols
[
{ name: 'Window', url: '/docs/c/Window/', language: 'c' },
{ name: 'Window', url: '/docs/pebblejs/Window/', language: 'pebblejs' }
]
end
end

View file

@ -0,0 +1,32 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
require 'simplecov'
SimpleCov.start
require 'dotenv'
Dotenv.load
require 'open-uri'
if OpenURI::Buffer.const_defined?('StringMax')
OpenURI::Buffer.send :remove_const, 'StringMax'
end
OpenURI::Buffer.const_set 'StringMax', 0
RSpec.configure do |config|
config.fail_fast = true
config.formatter = :documentation
config.color = true
end

View file

@ -0,0 +1,60 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
require 'redcarpet'
require 'jekyll'
require_relative '../lib/toc_generator'
describe Pebble::TocGenerator do
describe '#generate' do
before do
@toc = Pebble::TocGenerator.new
end
it 'returns empty array on blank document' do
expect(@toc.generate('')).to eql([])
end
it 'returns array of top level headers' do
document = "# Header 1\n\n#Header 2"
contents = @toc.generate(document)
expect(contents.size).to eql(2)
expect(contents[0][1]).to eql('Header 1')
expect(contents[1][0]).to eql('header-2')
expect(contents[1][2]).to eql(1)
end
it 'works for any depth of header' do
document = "# Header 1\n\n#### Header 2\n\n###### Header 3"
contents = @toc.generate(document)
expect(contents.size).to eql(3)
expect(contents[0][2]).to eql(1)
expect(contents[1][2]).to eql(4)
expect(contents[2][2]).to eql(6)
end
it 'normalises the headers so the smallest is 1' do
document = "#### Header 1\n\n###### Header 2"
contents = @toc.generate(document)
expect(contents.size).to eql(2)
expect(contents[0][2]).to eql(1)
expect(contents[1][2]).to eql(3)
end
end
end