#408 Use Markdown to render Sticky widget
Merged 6 years ago by abompard. Opened 6 years ago by shaily.
shaily/fedora-hubs sticky-markdown  into  develop

@@ -2,7 +2,6 @@ 

  <html lang='en'>

  <head>

    <title>{% block title %}{% endblock %}</title>

-   <link href="{{ url_for('static', filename='css/style-patternlab.css') }}" rel="stylesheet" />

    <link href="{{ url_for('static', filename='fedora-bootstrap/fedora-bootstrap.min.css') }}" rel="stylesheet" />

    <link href="{{ url_for('static', filename='css/style.css') }}" rel="stylesheet" />

    <link href="{{ url_for('static', filename='css/pace-theme-minimal.css') }}" rel="stylesheet" />

@@ -0,0 +1,25 @@ 

+ from __future__ import unicode_literals

+ 

+ from . import WidgetTest

+ 

+ 

+ class StickyTest(WidgetTest):

+ 

+     plugin = "sticky"

+     initial_widget_config = {

+         "text": """| Tables        | Are           | Cool  |

+                    | ------------- |:-------------:| -----:|

+                    | col 3 is      | right-aligned | $1600 |

+                    | col 2 is      | centered      |   $12 |

+                    | zebra stripes | are neat      |    $1 |

+                 """

+     }

+ 

+     def populate(self):

+         super(StickyTest, self).populate()

+         self._add_widget_under_test()

+ 

+     def test_markdown_parse(self):

+         func = self.widget.module.get_cached_functions()['ParseMarkdown']

+         result = func(self.widget).execute()

+         self.assertRegexpMatches(result, r'^<table>(?s).*</table>$')

@@ -2,8 +2,11 @@ 

  

  from hubs.widgets import validators

  from hubs.widgets.base import Widget

+ from hubs.widgets.caching import CachedFunction

  from hubs.widgets.view import RootWidgetView

  

+ from markdown import markdown

+ 

  

  class Sticky(Widget):

  
@@ -11,9 +14,12 @@ 

      label = "Sticky Note"

      position = "both"

      display_css = "card-info"

+     is_large = True

      parameters = [

          dict(

              name="text",

+             render_tag="textarea",

+             render_attributes={"rows": "30"},

              label="Text",

              default="Lorem ipsum dolor...",

              validator=validators.Text,
@@ -24,7 +30,18 @@ 

  class BaseView(RootWidgetView):

  

      def get_context(self, instance, *args, **kwargs):

-         # TODO -- render with markdown

+         md = ParseMarkdown(instance)

          return dict(

-             text=instance.config["text"],

-             )

+             text=md()

+         )

+ 

+ 

+ class ParseMarkdown(CachedFunction):

+ 

+     def execute(self):

+         text = self.instance.config["text"]

+         return markdown(text, extensions=['markdown.extensions.extra',

+                                           'markdown.extensions.sane_lists'])

+ 

+     def should_invalidate(self, message):

+         return False

file modified
+1
@@ -13,6 +13,7 @@ 

  fmn.rules

  gunicorn

  html5lib==0.9999999

+ markdown

  munch

  psycopg2

  pymongo

The first commit (129869f) is part of PR #407
The second commit (443932c) removes pattern lab's CSS as discussed in the meeting on 2017-10-17. The relevant style sheets from that are being merged into fedora-bootstrap.

rebased onto 443932c

6 years ago

Thanks. Could you add a small unit test for the cached function? Just verify a basic markdown conversion.

1 new commit added

  • Add markdown test for Sticky Note widget
6 years ago

3 new commits added

  • Add markdown test for Sticky Note widget
  • Add markdown rendering capability to Sticky Note widget
  • Remove pattern lab CSS
6 years ago

Pull-Request has been merged by abompard

6 years ago