Skip to content
This repository has been archived by the owner on Feb 26, 2022. It is now read-only.

Commit

Permalink
Merge pull request #701 from wbamberg/821774
Browse files Browse the repository at this point in the history
Fix for bug 821774(cherry picked from commit b323148)
  • Loading branch information
wbamberg committed Jan 18, 2013
1 parent acb4c2f commit ded1f5f
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 203 deletions.
2 changes: 1 addition & 1 deletion doc/static-files/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<input type="submit" name="sa" value="Search" />
</div>
</form>
<script type="text/javascript" src="http://www.google.com/cse/brand?form=cse-search-box&lang=en"></script>
<script type="text/javascript" src="https://www.google.com/cse/brand?form=cse-search-box&lang=en"></script>
<!-- Google CSE Search Box Ends -->
</div>
</div>
Expand Down
16 changes: 10 additions & 6 deletions python-lib/cuddlefish/docs/documentationitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class ModuleInfo(DocumentationItemInfo):
def __init__(self, env_root, module_root, md_path, filename):
DocumentationItemInfo.__init__(self, env_root, md_path, filename)
self.module_root = module_root
self.metadata = self.get_metadata(self.js_module_path())
self.metadata = self.get_metadata()

def remove_comments(self, text):
def replacer(match):
Expand All @@ -62,9 +62,11 @@ def replacer(match):
)
return re.sub(pattern, replacer, text)

def get_metadata(self, path_to_js):
def get_metadata(self):
if self.level() == "third-party":
return simplejson.loads("{}")
try:
js = unicode(open(path_to_js,"r").read(), 'utf8')
js = unicode(open(self.js_module_path(),"r").read(), 'utf8')
except IOError:
raise Exception, "JS module: '" + path_to_js + \
"', corresponding to documentation file: '"\
Expand All @@ -84,9 +86,6 @@ def get_metadata(self, path_to_js):
metadata = metadata.replace("'", '"')
return simplejson.loads("{" + metadata + "}")

def js_module_path(self):
return os.path.join(self.env_root, "lib", self.source_path_relative_from_module_root(), self.source_filename[:-len(".md")] + ".js")

def source_path_relative_from_module_root(self):
return self.source_path[len(self.module_root) + 1:]

Expand All @@ -98,6 +97,11 @@ def destination_path(self):
relative_pieces = self.source_path_relative_from_module_root().split(os.sep)
return os.sep.join(root_pieces + relative_pieces)

def js_module_path(self):
return os.path.join(self.env_root, "lib", \
self.source_path_relative_from_module_root(), \
self.source_filename[:-len(".md")] + ".js")

def relative_url(self):
if self.level() == "third-party":
relative_pieces = ["packages"]
Expand Down

This file was deleted.

161 changes: 0 additions & 161 deletions python-lib/cuddlefish/tests/static-files/doc/static-files/base.html

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello, I'm a third party.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

exports.main = function(options, callbacks) {
console.log("1 + 1 =", require("bar-module").add(1, 1));
callbacks.quit();
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"author": "Jon Smith",
"description": "A package w/ a main module; can be built into an extension.",
"keywords": ["potato"],
"version": "1.0",
"dependencies": ["addon-sdk", "barbeque"]
}
14 changes: 11 additions & 3 deletions python-lib/cuddlefish/tests/test_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
INITIAL_FILESET = [ ["static-files", "base.html"], \
["dev-guide", "index.html"], \
["modules", "sdk", "aardvark-feeder.html"], \
["modules", "sdk", "anteater", "anteater.html"]]
["modules", "sdk", "anteater", "anteater.html"], \
["modules", "packages", "third_party.html"]]

EXTENDED_FILESET = [ ["static-files", "base.html"], \
["dev-guide", "extra.html"], \
["dev-guide", "index.html"], \
["modules", "sdk", "aardvark-feeder.html"], \
["modules", "sdk", "anteater", "anteater.html"]]
["modules", "sdk", "anteater", "anteater.html"],\
["modules", "packages", "third_party.html"]]

EXTRAFILE = ["dev-guide", "extra.html"]

Expand Down Expand Up @@ -134,6 +136,11 @@ def cleanup():
def test_generate_docs(self):
test_root = get_test_root()
docs_root = os.path.join(test_root, "doc")
static_files_src = os.path.join(env_root, "doc", "static-files")
static_files_dst = os.path.join(test_root, "doc", "static-files")
if os.path.exists(static_files_dst):
shutil.rmtree(static_files_dst)
shutil.copytree(static_files_src, static_files_dst)
generate.clean_generated_docs(docs_root)
new_digest = self.check_generate_regenerate_cycle(test_root, INITIAL_FILESET)
# touching an MD file under sdk **does** cause a regenerate
Expand All @@ -143,7 +150,7 @@ def test_generate_docs(self):
os.utime(os.path.join(test_root, "doc", "module-source", "sdk", "not_a_doc.js"), None)
self.check_generate_is_skipped(test_root, INITIAL_FILESET, new_digest)
# touching a non MD file under static-files **does not** cause a regenerate
os.utime(os.path.join(docs_root, "static-files", "another.html"), None)
os.utime(os.path.join(docs_root, "static-files", "css", "sdk-docs.css"), None)
new_digest = self.check_generate_is_skipped(test_root, INITIAL_FILESET, new_digest)
# touching an MD file under dev-guide **does** cause a regenerate
os.utime(os.path.join(docs_root, "dev-guide-source", "index.md"), None)
Expand All @@ -156,6 +163,7 @@ def test_generate_docs(self):
new_digest = self.check_generate_regenerate_cycle(test_root, INITIAL_FILESET, new_digest)
# remove the files
generate.clean_generated_docs(docs_root)
shutil.rmtree(static_files_dst)

def check_generate_is_skipped(self, test_root, files_to_expect, initial_digest):
generate.generate_docs(test_root, stdout=StringIO.StringIO())
Expand Down
22 changes: 22 additions & 0 deletions python-lib/cuddlefish/tests/test_webdocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

import os
import unittest
import shutil

from cuddlefish.tests import env_root
from cuddlefish.docs import webdocs
from cuddlefish.docs.documentationitem import get_module_list
from cuddlefish.docs.documentationitem import get_devguide_list
Expand All @@ -14,10 +16,12 @@ class WebDocTests(unittest.TestCase):
def test_create_guide1_doc(self):
root = os.path.join(os.getcwd() + \
'/python-lib/cuddlefish/tests/static-files')
self.copy_static_files(root)
module_list = get_module_list(root)
web_docs = webdocs.WebDocs(root, module_list)
guide = web_docs.create_guide_page(os.path.join(\
root + '/doc/dev-guide-source/index.md'))
self.rm_static_files(root)
self._test_common_contents(guide)
self.assertTrue(\
'<title>An Imposing Title - Add-on SDK Documentation</title>'\
Expand All @@ -27,13 +31,16 @@ def test_create_guide1_doc(self):
self.assertTrue('<div id="version">Version '\
in guide)


def test_create_guide2_doc(self):
root = os.path.join(os.getcwd() + \
'/python-lib/cuddlefish/tests/static-files')
self.copy_static_files(root)
module_list = get_module_list(root)
web_docs = webdocs.WebDocs(root, module_list)
guide = web_docs.create_guide_page(os.path.join(\
root + '/doc/dev-guide-source/no_h1.md'))
self.rm_static_files(root)
self._test_common_contents(guide)
self.assertTrue('<title>Add-on SDK Documentation</title>'\
in guide)
Expand All @@ -43,6 +50,7 @@ def test_create_guide2_doc(self):
def test_create_module_doc(self):
root = os.path.join(os.getcwd() + \
'/python-lib/cuddlefish/tests/static-files')
self.copy_static_files(root)
module_list = get_module_list(root)
test_module_info = False
for module_info in module_list:
Expand All @@ -54,6 +62,7 @@ def test_create_module_doc(self):
self.assertEqual(test_stability, "stable")
web_docs = webdocs.WebDocs(root, module_list)
module = web_docs.create_module_page(test_module_info)
self.rm_static_files(root)
self._test_common_contents(module)
self.assertTrue(\
'<title>aardvark-feeder - Add-on SDK Documentation</title>'\
Expand Down Expand Up @@ -89,5 +98,18 @@ def _test_common_contents(self, doc):
self.assertTrue(\
'<a href="modules/sdk/aardvark-feeder.html">aardvark-feeder</a>' in doc)

def static_files_dir(self, root):
return os.path.join(root, "doc", "static-files")

def copy_static_files(self, test_root):
self.rm_static_files(test_root)
static_files_src = self.static_files_dir(env_root)
static_files_dst = self.static_files_dir(test_root)
shutil.copytree(static_files_src, static_files_dst)

def rm_static_files(self, test_root):
if os.path.exists(self.static_files_dir(test_root)):
shutil.rmtree(self.static_files_dir(test_root))

if __name__ == "__main__":
unittest.main()

0 comments on commit ded1f5f

Please sign in to comment.