22 Commits 85b0d87d34 ... d575fc9b31

Author SHA1 Message Date
  rsiddharth d575fc9b31 lpschedule_generator/_version.py: Bump to 0.10.0. 5 years ago
  rsiddharth b97e19d8ed lps_gen.py: Update LPiCal.gen_ical. 5 years ago
  rsiddharth d36e9301c5 setup.py: Update config. 5 years ago
  rsiddharth 1a45b44066 lpschedule_generator/_version.py: Bump to 0.10.dev1 5 years ago
  rsiddharth f34b276dd9 tests: Update test_lps_gen.py. 5 years ago
  rsiddharth 302b5e0964 lps_gen: Rename '-s' switch to '-sc' 5 years ago
  rsiddharth f3534a95c1 test_lps_gen.py: Remove reference to paths of templates. 5 years ago
  rsiddharth 2bfb8a5291 lps_gen.py: Update main. 5 years ago
  rsiddharth 7386352cdd tests/test_lps_gen.py: Update TestTemplates. 5 years ago
  rsiddharth 73ccb20703 lps_gen: Remove `lp_t` command line argument. 5 years ago
  rsiddharth b202aa341f lps_gen.py: Update template_read. 5 years ago
  rsiddharth df19a818d8 lps_gen.py: Update template_read. 5 years ago
  rsiddharth 8ca7c73df5 lps_gen.py: Add template_read. 5 years ago
  rsiddharth 067cba74f5 tests: Update test_lps_gen.py. 5 years ago
  rsiddharth e91db3f5cc setup.py: Update config. 5 years ago
  rsiddharth a0509c1c68 setup.py: Update config. 5 years ago
  rsiddharth ec1dca1a87 setup.py: Update config. 5 years ago
  rsiddharth 17651759b0 Remove libreplanet-templates/2018/lp-schedule.jinja2 5 years ago
  rsiddharth 1bacddac8a Remove libreplanet-templates/2017/lp-schedule.jinja2 5 years ago
  rsiddharth 054d04aa6a Remove libreplanet-templates/2016/lp-schedule.jinja2 5 years ago
  rsiddharth e6161cf8dc libreplanet-templates/2019/lp-schedule.jinja2 -> lpschedule_generator/data/schedule.jinja2 5 years ago
  rsiddharth dc94a41802 libreplanet-templates/2016/lp-speakers.jinja2 -> lpschedule_generator/data/speakers.jinja2 5 years ago

+ 2 - 3
docs/install/index.rst

@@ -67,15 +67,14 @@ Do::
 
 You must get::
 
-  usage: lps_gen [-h] [-s | -sp] [--ical ICAL] [--version] lp_t lp_md
+  usage: lps_gen [-h] [-sc | -sp] [--ical ICAL] [--version] lp_md
 
   positional arguments:
-    lp_t             Path to the LP template.
     lp_md            Path to the LP markdown.
 
   optional arguments:
     -h, --help       show this help message and exit
-    -s, --schedule   Generate LP schedule
+    -sc, --schedule  Generate LP schedule
     -sp, --speakers  Generate LP speakers
     --ical ICAL      Specify LP year as argument; generates iCal
     --version        Show version number and exit.

+ 3 - 3
docs/schedule/index.rst

@@ -188,11 +188,11 @@ Generate HTML from Markdown
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
 ::
 
-   $ lps_gen -s path/to/lp-sch.jinja2 path/to/lp-sch.md > path/to/program-schedule.html
+   $ lps_gen -sc path/to/lp-sch.md > path/to/program-schedule.html
 
 or::
 
-  $ lps_gen --schedule path/to/lp-schedule.jinja2 path/to/lp-sch.md > path/to/program-schedule.html
+  $ lps_gen --schedule path/to/lp-sch.md > path/to/program-schedule.html
 
 
 iCal export
@@ -201,7 +201,7 @@ iCal export
 The ``--ical`` switch enables iCal export while generating LP
 schedule::
 
-  $ lps_gen -s --ical 2016 path/to/lp-schedule.jinja2 path/to/lp-schedule.md > path/to/program-schedule.html
+  $ lps_gen -sc --ical 2016 path/to/lp-schedule.md > path/to/program-schedule.html
 
 The year of the conference must be given as an argument to the
 ``--ical`` switch.

+ 2 - 2
docs/speakers/index.rst

@@ -63,11 +63,11 @@ Generate HTML from Markdown
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
 ::
 
-   $ lps_gen -sp path/to/lp-speakers.jinja2 path/to/lp-speakers.md > path/to/speakers-content.html
+   $ lps_gen -sp path/to/lp-speakers.md > path/to/speakers-content.html
 
 or::
 
-  $ lps_gen --speakers path/to/lp-speakers.jinja2 path/to/lp-speakers.md > path/to/speakers-content.html
+  $ lps_gen --speakers path/to/lp-speakers.md > path/to/speakers-content.html
 
 If you run into issues, ask for :ref:`help <lps-doc-sec-help>`.
 

+ 0 - 115
libreplanet-templates/2016/lp-schedule.jinja2

@@ -1,115 +0,0 @@
-{# -*- mode: jinja2; -*- #}
-{#
-    SPDX-License-Identifier: CC0-1.0
-
-    This file is part of lpschedule-generator.
-#}
-
-{# macros start #}
-
-{# make speakers macro #}
-{% macro mk_speakers(speakers) %}
-  {% if speakers[0]|lower != 'speakertba' %}
-    <span class="program-session-speaker">
-      {% for speaker in speakers %}
-        {% if loop.last %}
-          {{ speaker }}
-        {% else %}
-          {{ speaker }},
-        {% endif %}
-      {% endfor %}
-    </span>
-  {% endif %}
-{% endmacro %}
-
-{# make room macro #}
-{% macro mk_room(room) %}
-  {% if room|lower != 'roomtba' %}
-    <span class="room label label-default">{{ room }}</span>
-  {% endif %}
-{% endmacro %}
-
-{# make day header macro #}
-{% macro mk_day_header(day, collapse_area) %}
-  {% if day|trim != '' %}
-    <header class="program-day-header">
-      <hgroup>
-        <h2>{{ day }}</h2>
-      </hgroup>
-    </header>
-  {% endif %}
-{% endmacro %}
-
-{# make timeslot header macro #}
-{% macro mk_timeslot_header(timeslot, collapse, collapse_area='') %}
-  {% if timeslot|trim != '' %}
-    <header class="program-timeslot-header">
-      <hgroup>
-        <h2>{{ timeslot }}</h2>
-      </hgroup>
-    </header>
-  {% endif %}
-{% endmacro %}
-
-{# make session header macro #}
-{% macro mk_session_header(session) %}
-  <header class="program-session-header">
-    <hgroup>
-      <h2>{{ session }}</h2>
-    </hgroup>
-  </header>
-{% endmacro %}
-
-{# desc macro #}
-{% macro desc(disc_list) %}
-  {% for desc_p in disc_list %}
-    <p>{{ desc_p }}</p>
-  {% endfor %}
-{% endmacro %}
-
-{# populate sessions macro #}
-{% macro populate_sessions(sessions, day_index, timeslot_index) %}
-  {% for session, session_info in sessions.iteritems() %} {# session start #}
-    <section id="day-{{ day_index }}-timeslot-{{ timeslot_index }}-session-{{ loop.index }}" class="program-session">
-      {{ mk_session_header(session) }}
-      {{ mk_speakers(session_info['speakers']) }}
-      <p class="program-session-room-details">
-        {{ mk_room(session_info['room']) }}
-        {% if session_info['desc'][0]|lower == 'desctba' %}
-          </p>
-        {% else %}
-          <button class="btn btn-default btn-xs"
-                  data-toggle="collapse" aria-expanded="false"
-                  aria-controls="day-{{ day_index }}-timeslot-{{ timeslot_index }}-session-{{ loop.index }}-collapse"
-                  data-target="#day-{{ day_index }}-timeslot-{{ timeslot_index }}-session-{{ loop.index }}-collapse">
-                  Details
-          </button>
-          </p>
-          <div class="session-desc collapse in"
-               id="day-{{ day_index }}-timeslot-{{ timeslot_index }}-session-{{ loop.index }}-collapse">
-               {{ desc(session_info['desc']) }}
-          </div> <!-- day-{{ day_index }}-timeslot-{{ timeslot_index }}-session-{{ loop.index }}-collapse end -->
-        {% endif %}
-    </section> <!-- day-{{ day_index }}-timeslot-{{ timeslot_index }}-session-{{ loop.index }} end -->
-  {% endfor %} {# session end #}
-{% endmacro %}
-
-{# populate timeslots macro #}
-{% macro populate_timeslots(timeslots, day_index) %}
-  {% for timeslot, sessions in timeslots.iteritems() %}  {# timeslot start #}
-    <article id="day-{{ day_index }}-timeslot-{{ loop.index }}" class="program-timeslot">
-      {{ mk_timeslot_header(timeslot) }}
-      {% if sessions|length > 0 %}
-             {{ populate_sessions(sessions, day_index, loop.index) }}
-      {% endif %}
-    </article> <!-- day-{{ day_index }}-timeslot-{{ loop.index }} end -->
-  {% endfor %} {# timeslot start #}
-{% endmacro %}
-
-{# lp schedule 2016 template start #}
-{% for day, timeslots in lp_dict.iteritems() %} {# day start #}
-  <article id="day-{{ loop.index }}-program" class="program-day">
-    {{ mk_day_header(day) }}
-      {{ populate_timeslots(timeslots, loop.index) }}
-  </article> <!-- day-{{ loop.index }} end -->
-{% endfor %} {# day loop end #}

+ 0 - 116
libreplanet-templates/2017/lp-schedule.jinja2

@@ -1,116 +0,0 @@
-{# -*- mode: jinja2; -*- #}
-{#
-    SPDX-License-Identifier: CC0-1.0
-
-    This file is part of lpschedule-generator.
-#}
-
-{# macros start #}
-
-{# make speakers macro #}
-{% macro mk_speakers(speakers) %}
-  {% if speakers[0]|lower != 'speakertba' %}
-    <span class="program-session-speaker">
-      {% for speaker in speakers %}
-        {% if loop.last %}
-          {{ speaker }}
-        {% else %}
-          {{ speaker }},
-        {% endif %}
-      {% endfor %}
-    </span>
-  {% endif %}
-{% endmacro %}
-
-{# make room macro #}
-{% macro mk_room(room) %}
-  {% if room|lower != 'roomtba' %}
-    <span class="room label label-default">{{ room }}</span>
-  {% endif %}
-{% endmacro %}
-
-{# make day header macro #}
-{% macro mk_day_header(day, collapse_area) %}
-  {% if day|trim != '' %}
-    <header class="program-day-header">
-      <hgroup>
-        <h2>{{ day }}</h2>
-      </hgroup>
-    </header>
-  {% endif %}
-{% endmacro %}
-
-{# make timeslot header macro #}
-{% macro mk_timeslot_header(timeslot, collapse, collapse_area='') %}
-  {% if timeslot|trim != '' %}
-    <header class="program-timeslot-header">
-      <hgroup>
-        <h2>{{ timeslot }}</h2>
-      </hgroup>
-    </header>
-  {% endif %}
-{% endmacro %}
-
-{# make session header macro #}
-{% macro mk_session_header(session) %}
-  <header class="program-session-header">
-    <hgroup>
-      <h2>{{ session }}</h2>
-    </hgroup>
-  </header>
-{% endmacro %}
-
-{# desc macro #}
-{% macro desc(disc_list) %}
-  {% for desc_p in disc_list %}
-    <p>{{ desc_p }}</p>
-  {% endfor %}
-{% endmacro %}
-
-{# populate sessions macro #}
-{% macro populate_sessions(sessions, day_index, timeslot_index) %}
-  {% for session, session_info in sessions.iteritems() %} {# session start #}
-    <section id="day-{{ day_index }}-timeslot-{{ timeslot_index }}-session-{{ loop.index }}" class="program-session">
-      {{ mk_session_header(session) }}
-      {{ mk_speakers(session_info['speakers']) }}
-      <p class="program-session-room-details">
-        {{ mk_room(session_info['room']) }}
-        {% if session_info['desc'][0]|lower == 'desctba' %}
-          </p>
-        {% else %}
-          <button class="btn btn-default btn-xs"
-                  data-toggle="collapse" aria-expanded="false"
-                  aria-controls="day-{{ day_index }}-timeslot-{{ timeslot_index }}-session-{{ loop.index }}-collapse"
-                  data-target="#day-{{ day_index }}-timeslot-{{ timeslot_index }}-session-{{ loop.index }}-collapse">
-                  Show details
-                  <span class="glyphicon glyphicon-menu-down" aria-hidden="true"></span>
-          </button>
-          </p>
-          <div class="session-desc collapse in"
-               id="day-{{ day_index }}-timeslot-{{ timeslot_index }}-session-{{ loop.index }}-collapse">
-               {{ desc(session_info['desc']) }}
-          </div> <!-- day-{{ day_index }}-timeslot-{{ timeslot_index }}-session-{{ loop.index }}-collapse end -->
-        {% endif %}
-    </section> <!-- day-{{ day_index }}-timeslot-{{ timeslot_index }}-session-{{ loop.index }} end -->
-  {% endfor %} {# session end #}
-{% endmacro %}
-
-{# populate timeslots macro #}
-{% macro populate_timeslots(timeslots, day_index) %}
-  {% for timeslot, sessions in timeslots.iteritems() %}  {# timeslot start #}
-    <article id="day-{{ day_index }}-timeslot-{{ loop.index }}" class="program-timeslot">
-      {{ mk_timeslot_header(timeslot) }}
-      {% if sessions|length > 0 %}
-             {{ populate_sessions(sessions, day_index, loop.index) }}
-      {% endif %}
-    </article> <!-- day-{{ day_index }}-timeslot-{{ loop.index }} end -->
-  {% endfor %} {# timeslot start #}
-{% endmacro %}
-
-{# lp schedule 2016 template start #}
-{% for day, timeslots in lp_dict.iteritems() %} {# day start #}
-  <article id="day-{{ loop.index }}-program" class="program-day">
-    {{ mk_day_header(day) }}
-      {{ populate_timeslots(timeslots, loop.index) }}
-  </article> <!-- day-{{ loop.index }} end -->
-{% endfor %} {# day loop end #}

+ 0 - 146
libreplanet-templates/2018/lp-schedule.jinja2

@@ -1,146 +0,0 @@
-{# -*- mode: jinja2; -*- #}
-{#
-    SPDX-License-Identifier: CC0-1.0
-
-    This file is part of lpschedule-generator.
-#}
-
-{# macros start #}
-
-{# make speakers macro #}
-{% macro mk_speakers(speakers) %}
-  {% if speakers[0]|lower != 'speakertba' %}
-    <div class="program-session-speaker">
-      {% for speaker in speakers %}
-        {% if loop.last %}
-          {{ speaker }}
-        {% else %}
-          {{ speaker }},
-        {% endif %}
-      {% endfor %}
-    </div>
-  {% endif %}
-{% endmacro %}
-
-{# make room macro #}
-{% macro mk_room(room) %}
-  {% if room|lower != 'roomtba' %}
-    <div class="program-session-room-details">
-      <span class="room label label-default">{{ room }}</span>
-    </div>
-  {% endif %}
-{% endmacro %}
-
-{# make video macro #}
-{% macro mk_video(video) %}
-  {% if video|lower != 'videotba' %}
-    <a class="btn btn-default btn-xs" href="{{ video }}">
-      <span class="glyphicon glyphicon-facetime-video"></span>
-    </a>
-  {% endif %}
-{% endmacro %}
-
-{# make desc details button macro #}
-{% macro mk_desc_details_btn(disc_list) %}
-  {% if disc_list[0]|lower != 'desctba' %}
-    <button class="btn btn-default btn-xs"
-            data-toggle="collapse" aria-expanded="false"
-            aria-controls="{{ caller()|trim }}"
-            data-target="#{{ caller()|trim }}">
-            Show details
-            <span class="glyphicon glyphicon-menu-down" aria-hidden="true"></span>
-    </button>
-  {% endif %}
-{% endmacro %}
-
-{% macro mk_desc(disc_list) %}
-  {% if disc_list[0]|lower != 'desctba' %}
-    <div class="session-desc collapse in"
-         id="{{ caller()|trim }}">
-         {{ desc(disc_list) }}
-    </div> <!--  {{ caller()|trim }} end -->
-  {% endif %}
-{% endmacro %}
-
-{# make day header macro #}
-{% macro mk_day_header(day, collapse_area) %}
-  {% if day|trim != '' %}
-    <header class="program-day-header">
-      <hgroup>
-        <h2>{{ day }}</h2>
-      </hgroup>
-    </header>
-  {% endif %}
-{% endmacro %}
-
-{# make timeslot header macro #}
-{% macro mk_timeslot_header(timeslot, collapse, collapse_area='') %}
-  {% if timeslot|trim != '' %}
-    <header class="program-timeslot-header">
-      <hgroup>
-        <h2>{{ timeslot }}</h2>
-      </hgroup>
-    </header>
-  {% endif %}
-{% endmacro %}
-
-{# make session header macro #}
-{% macro mk_session_header(session) %}
-  {% if session|trim not in ['', 'st-from-ts'] %}
-    <header class="program-session-header">
-      <hgroup>
-        <h2>{{ session }}</h2>
-      </hgroup>
-  </header>
-  {% endif %}
-{% endmacro %}
-
-{# desc macro #}
-{% macro desc(disc_list) %}
-  {% for desc_p in disc_list %}
-    <p>{{ desc_p }}</p>
-  {% endfor %}
-{% endmacro %}
-
-{# populate sessions macro #}
-{% macro populate_sessions(sessions, day_index, timeslot_index) %}
-  {% for session, session_info in sessions.iteritems() %} {# session start #}
-    <section id="day-{{ day_index }}-timeslot-{{ timeslot_index }}-session-{{ loop.index }}" class="program-session">
-      {{ mk_session_header(session) }}
-      {{ mk_speakers(session_info['speakers']) }}
-      <div class="program-session-shelf">
-        {{ mk_room(session_info['room']) }}
-        {{ mk_video(session_info['video']) }}
-        {% call mk_desc_details_btn(session_info['desc']) %}
-          day-{{ day_index }}-timeslot-{{ timeslot_index }}-session-{{ loop.index }}-collapse
-        {% endcall %}
-      </div>
-
-      <div class="program-session-desc-block">
-        {% call mk_desc(session_info['desc']) %}
-          day-{{ day_index }}-timeslot-{{ timeslot_index }}-session-{{ loop.index }}-collapse
-        {% endcall %}
-      </div>
-    </section> <!-- day-{{ day_index }}-timeslot-{{ timeslot_index }}-session-{{ loop.index }} end -->
-  {% endfor %} {# session end #}
-{% endmacro %}
-
-{# populate timeslots macro #}
-{% macro populate_timeslots(timeslots, day_index) %}
-  {% for timeslot, sessions in timeslots.iteritems() %}  {# timeslot start #}
-    <article id="day-{{ day_index }}-timeslot-{{ loop.index }}" class="program-timeslot">
-      {{ mk_timeslot_header(timeslot) }}
-      {% if sessions|length > 0 %}
-             {{ populate_sessions(sessions, day_index, loop.index) }}
-      {% endif %}
-    </article> <!-- day-{{ day_index }}-timeslot-{{ loop.index }} end -->
-  {% endfor %} {# timeslot start #}
-{% endmacro %}
-
-{# lp schedule 2016 template start #}
-{% for day, timeslots in lp_dict.iteritems() %} {# day start #}
-  <article id="day-{{ loop.index }}-program" class="program-day">
-    {{ mk_day_header(day) }}
-      {{ populate_timeslots(timeslots, loop.index) }}
-  </article> <!-- day-{{ loop.index }} end -->
-{% endfor %} {# day loop end #}

+ 32 - 19
lps_gen.py

@@ -10,6 +10,7 @@ import json
 import re
 import sys
 
+import pkg_resources as pkgr
 import pytz
 
 from argparse import ArgumentParser
@@ -92,6 +93,21 @@ def json_read(filename):
                       object_pairs_hook=OrderedDict)
 
 
+def template_read(name):
+    """Return template as `str`.
+    """
+    p = 'lpschedule_generator'
+    r = 'data/{}.jinja2'.format(name)
+
+    t = None
+    try:
+        t = pkgr.resource_string(p, r).decode('utf-8')
+    except Exception as e:
+        print(e, file=sys.stderr)
+
+    return t
+
+
 class LPiCal(object):
     """Used for producing iCal for LP schedule.
     """
@@ -261,7 +277,7 @@ class LPiCal(object):
                     self.add_event(month, day, t_start, t_end, t_name,
                                    session, session_info)
 
-        return str(self.cal.to_ical())
+        return self.cal.to_ical().decode('utf-8')
 
 
     def to_ical(self):
@@ -588,22 +604,19 @@ class LPSpeakersMarkdown(Markdown):
         return lpspeakers_dict
 
 
-def RenderHTML(lp_dict, template):
+def RenderHTML(lp_dict, template_name):
     """Renders LP schedule/speakers in HTML from a python dictionary.
 
     Returns the HTML as a string.
     """
-    env = Environment(loader=FileSystemLoader(path.dirname(template)),
-                      trim_blocks=True, lstrip_blocks=True)
+    template_content = template_read(template_name)
+    if not template_content:
+        exit('Unable to read {} template'.format(template_name))
 
-    template_name = path.basename(template)
-    template  = None
-
-    try:
-        template = env.get_template(template_name)
-    except TemplateNotFound as e:
-        print('Template {} not found.'.format(template_name))
-        exit(1)
+    template = Environment(
+        trim_blocks=True,
+        lstrip_blocks=True
+    ).from_string(template_content)
 
     lp_html = template.render(lp_dict=lp_dict)
 
@@ -614,7 +627,7 @@ def main():
     parser = ArgumentParser()
 
     group = parser.add_mutually_exclusive_group()
-    group.add_argument("-s", "--schedule", action="store_true",
+    group.add_argument("-sc", "--schedule", action="store_true",
                        help="Generate LP schedule")
     group.add_argument("-sp", "--speakers", action="store_true",
                        help="Generate LP speakers")
@@ -626,32 +639,32 @@ def main():
                         version='lpschedule-generator version {}'
                         .format(__version__),
                         help="Show version number and exit.")
-    parser.add_argument("lp_t",
-                        help="Path to the LP template.")
     parser.add_argument("lp_md",
                         help="Path to the LP markdown.")
     args = parser.parse_args()
 
-    lp_template = args.lp_t
     lp_md_content = read_file(path.abspath(args.lp_md))
 
-    if path.exists(lp_template) and lp_md_content:
+    if lp_md_content:
+        template_name = ''
 
         if args.schedule:
             markdown = LPSMarkdown()
+            template_name = 'schedule'
         elif args.speakers:
             markdown = LPSpeakersMarkdown()
+            template_name = 'speakers'
         else:
             parser.error('No action requested, add -s or -sp switch')
 
         lp_dict = markdown(lp_md_content)
-        lp_html = RenderHTML(lp_dict, lp_template)
+        lp_html = RenderHTML(lp_dict, template_name)
 
         if args.ical and args.schedule:
             LPiCal(lp_dict, args.ical).to_ical()
 
     else:
-        exit(1)
+        exit('Unable to read LP markdown')
 
     if lp_html:
         # stdout lps html

+ 1 - 1
lpschedule_generator/_version.py

@@ -5,4 +5,4 @@
 #   This file is part of lpschedule-generator.
 #
 
-__version__ = u'0.9.0'
+__version__ = u'0.10.0'

libreplanet-templates/2019/lp-schedule.jinja2 → lpschedule_generator/data/schedule.jinja2


+ 0 - 0
libreplanet-templates/2016/lp-speakers.jinja2


Some files were not shown because too many files changed in this diff