[gnome-builder] html-preview: switch to using gresources
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] html-preview: switch to using gresources
- Date: Wed, 20 Sep 2017 04:31:47 +0000 (UTC)
commit caf8018a0d7c3caf1c283afbc3ad3347845e0b83
Author: Christian Hergert <chergert redhat com>
Date: Tue Sep 19 21:31:35 2017 -0700
html-preview: switch to using gresources
.../{html_preview_plugin => css}/markdown.css | 0
.../{html_preview_plugin => }/gtk/menus.ui | 0
plugins/html-preview/html-preview.gresource.xml | 9 ++++++
plugins/html-preview/html-preview.plugin | 2 +-
.../__init__.py => html_preview.py} | 28 ++++++++++----------
.../{html_preview_plugin => js}/markdown-view.js | 0
.../{html_preview_plugin => js}/marked.js | 0
plugins/html-preview/meson.build | 17 +++++------
8 files changed, 32 insertions(+), 24 deletions(-)
---
diff --git a/plugins/html-preview/html_preview_plugin/markdown.css b/plugins/html-preview/css/markdown.css
similarity index 100%
rename from plugins/html-preview/html_preview_plugin/markdown.css
rename to plugins/html-preview/css/markdown.css
diff --git a/plugins/html-preview/html_preview_plugin/gtk/menus.ui b/plugins/html-preview/gtk/menus.ui
similarity index 100%
rename from plugins/html-preview/html_preview_plugin/gtk/menus.ui
rename to plugins/html-preview/gtk/menus.ui
diff --git a/plugins/html-preview/html-preview.gresource.xml b/plugins/html-preview/html-preview.gresource.xml
new file mode 100644
index 0000000..bcc1fe4
--- /dev/null
+++ b/plugins/html-preview/html-preview.gresource.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+ <gresource prefix="/org/gnome/builder/plugins/html_preview">
+ <file>js/markdown-view.js</file>
+ <file>js/marked.js</file>
+ <file>css/markdown.css</file>
+ <file>gtk/menus.ui</file>
+ </gresource>
+</gresources>
diff --git a/plugins/html-preview/html-preview.plugin b/plugins/html-preview/html-preview.plugin
index 0fcb6d6..4b6c7d7 100644
--- a/plugins/html-preview/html-preview.plugin
+++ b/plugins/html-preview/html-preview.plugin
@@ -1,5 +1,5 @@
[Plugin]
-Module=html_preview_plugin
+Module=html_preview
Loader=python3
Name=HTML, reStructuredText and Markdown Preview
Description=Live preview of HTML, reStructuredText and Markdown documents.
diff --git a/plugins/html-preview/html_preview_plugin/__init__.py b/plugins/html-preview/html_preview.py
similarity index 95%
rename from plugins/html-preview/html_preview_plugin/__init__.py
rename to plugins/html-preview/html_preview.py
index aea51e0..7e7261b 100644
--- a/plugins/html-preview/html_preview_plugin/__init__.py
+++ b/plugins/html-preview/html_preview.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
#
-# html_preview_plugin.py
+# html_preview.py
#
# Copyright (C) 2015 Christian Hergert <chris dronelabs com>
#
@@ -101,16 +101,19 @@ class SphinxState():
self.is_running = False
self.need_build = False
-
class HtmlPreviewData(GObject.Object, Ide.ApplicationAddin):
MARKDOWN_CSS = None
MARKED_JS = None
MARKDOWN_VIEW_JS = None
def do_load(self, app):
- HtmlPreviewData.MARKDOWN_CSS = self.get_data('markdown.css')
- HtmlPreviewData.MARKED_JS = self.get_data('marked.js')
- HtmlPreviewData.MARKDOWN_VIEW_JS = self.get_data('markdown-view.js')
+ HtmlPreviewData.MARKDOWN_CSS = self.get_data('css/markdown.css')
+ HtmlPreviewData.MARKED_JS = self.get_data('js/marked.js')
+ HtmlPreviewData.MARKDOWN_VIEW_JS = self.get_data('js/markdown-view.js')
+
+ assert HtmlPreviewData.MARKDOWN_CSS
+ assert HtmlPreviewData.MARKED_JS
+ assert HtmlPreviewData.MARKDOWN_VIEW_JS
def do_unload(self, app):
for state in sphinx_states.items():
@@ -120,12 +123,9 @@ class HtmlPreviewData(GObject.Object, Ide.ApplicationAddin):
shutil.rmtree(state.builddir)
def get_data(self, name):
- engine = Peas.Engine.get_default()
- info = engine.get_plugin_info('html_preview_plugin')
- datadir = info.get_data_dir()
- path = os.path.join(datadir, name)
- return open(path, 'r').read()
-
+ # Hold onto the GBytes to avoid copying the buffer
+ path = os.path.join('/org/gnome/builder/plugins/html_preview', name)
+ return Gio.resources_lookup_data(path, 0)
class HtmlWorkbenchAddin(GObject.Object, Ide.WorkbenchAddin):
def do_load(self, workbench):
@@ -376,10 +376,10 @@ class HtmlPreviewView(Ide.LayoutView):
def get_markdown(self, text):
text = text.replace("\"", "\\\"").replace("\n", "\\n")
- params = (HtmlPreviewData.MARKDOWN_CSS,
+ params = (HtmlPreviewData.MARKDOWN_CSS.get_data().decode('UTF-8'),
text,
- HtmlPreviewData.MARKED_JS,
- HtmlPreviewData.MARKDOWN_VIEW_JS)
+ HtmlPreviewData.MARKED_JS.get_data().decode('UTF-8'),
+ HtmlPreviewData.MARKDOWN_VIEW_JS.get_data().decode('UTF-8'))
return """
<html>
diff --git a/plugins/html-preview/html_preview_plugin/markdown-view.js
b/plugins/html-preview/js/markdown-view.js
similarity index 100%
rename from plugins/html-preview/html_preview_plugin/markdown-view.js
rename to plugins/html-preview/js/markdown-view.js
diff --git a/plugins/html-preview/html_preview_plugin/marked.js b/plugins/html-preview/js/marked.js
similarity index 100%
rename from plugins/html-preview/html_preview_plugin/marked.js
rename to plugins/html-preview/js/marked.js
diff --git a/plugins/html-preview/meson.build b/plugins/html-preview/meson.build
index b58dc8e..299493c 100644
--- a/plugins/html-preview/meson.build
+++ b/plugins/html-preview/meson.build
@@ -1,15 +1,14 @@
if get_option('with_html_preview')
-html_preview_datadir = join_paths(plugindatadir, 'html_preview_plugin')
-html_preview_dir = join_paths(plugindir, 'html_preview_plugin')
+html_preview_resources = gnome.compile_resources(
+ 'html_preview',
+ 'html-preview.gresource.xml',
+ gresource_bundle: true,
+ install: true,
+ install_dir: plugindir,
+)
-install_data('html_preview_plugin/__init__.py', install_dir: html_preview_dir)
-install_data([
- 'html_preview_plugin/markdown-view.js',
- 'html_preview_plugin/markdown.css',
- 'html_preview_plugin/marked.js',
-], install_dir: html_preview_datadir)
-install_subdir('html_preview_plugin/gtk', install_dir: html_preview_datadir)
+install_data('html_preview.py', install_dir: plugindir)
configure_file(
input: 'html-preview.plugin',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]