Mercurial > libervia-backend
comparison frontends/src/jp/cmd_blog.py @ 2325:760df3a58c24
jp (blog/edit): syntax modifications:
- adapted to new behaviour (keys which are names in lower case en stripped are now used)
- added --syntax so force a specific syntax. If not used, profile's default syntax will be used
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 13 Jul 2017 20:55:35 +0200 |
parents | 4fd010f29f99 |
children | dad500e7ae50 |
comparison
equal
deleted
inserted
replaced
2324:fe922e6fabd4 | 2325:760df3a58c24 |
---|---|
38 __commands__ = ["Blog"] | 38 __commands__ = ["Blog"] |
39 | 39 |
40 # extensions to use with known syntaxes | 40 # extensions to use with known syntaxes |
41 SYNTAX_EXT = { | 41 SYNTAX_EXT = { |
42 '': 'txt', # used when the syntax is not found | 42 '': 'txt', # used when the syntax is not found |
43 "XHTML": "xhtml", | 43 "xhtml": "xhtml", |
44 "markdown": "md" | 44 "markdown": "md" |
45 } | 45 } |
46 | 46 |
47 | 47 |
48 CONF_SYNTAX_EXT = 'syntax_ext_dict' | 48 CONF_SYNTAX_EXT = 'syntax_ext_dict' |
284 self.parser.add_argument("item", type=base.unicode_decoder, nargs='?', default=u'new', help=_(u"URL of the item to edit, or keyword")) | 284 self.parser.add_argument("item", type=base.unicode_decoder, nargs='?', default=u'new', help=_(u"URL of the item to edit, or keyword")) |
285 self.parser.add_argument("-P", "--preview", action="store_true", help=_(u"launch a blog preview in parallel")) | 285 self.parser.add_argument("-P", "--preview", action="store_true", help=_(u"launch a blog preview in parallel")) |
286 self.parser.add_argument("-T", '--title', type=base.unicode_decoder, help=_(u"title of the item")) | 286 self.parser.add_argument("-T", '--title', type=base.unicode_decoder, help=_(u"title of the item")) |
287 self.parser.add_argument("-t", '--tag', type=base.unicode_decoder, action='append', help=_(u"tag (category) of your item")) | 287 self.parser.add_argument("-t", '--tag', type=base.unicode_decoder, action='append', help=_(u"tag (category) of your item")) |
288 self.parser.add_argument("--no-comment", action='store_true', help=_(u"disable comments")) | 288 self.parser.add_argument("--no-comment", action='store_true', help=_(u"disable comments")) |
289 self.parser.add_argument("-S", '--syntax', type=base.unicode_decoder, help=_(u"syntax to use (default: get profile's default syntax)")) | |
289 common.BaseEdit.add_parser_options(self) | 290 common.BaseEdit.add_parser_options(self) |
290 | 291 |
291 def buildMetadataFile(self, content_file_path, mb_data=None): | 292 def buildMetadataFile(self, content_file_path, mb_data=None): |
292 """Build a metadata file using json | 293 """Build a metadata file using json |
293 | 294 |
350 | 351 |
351 # we launch editor | 352 # we launch editor |
352 self.runEditor("blog_editor_args", content_file_path, content_file_obj, meta_file_path=meta_file_path, meta_ori=meta_ori) | 353 self.runEditor("blog_editor_args", content_file_path, content_file_obj, meta_file_path=meta_file_path, meta_ori=meta_ori) |
353 | 354 |
354 def publish(self, content, mb_data): | 355 def publish(self, content, mb_data): |
355 mb_data['content_rich'] = content | 356 if self.args.syntax is None: |
357 # default syntax has been used | |
358 mb_data['content_rich'] = content | |
359 else: | |
360 mb_data['content_xhtml'] = self.host.bridge.syntaxConvert(content, self.current_syntax, 'XHTML', False, self.profile) | |
356 | 361 |
357 if self.pubsub_item is not None: | 362 if self.pubsub_item is not None: |
358 mb_data['id'] = self.pubsub_item | 363 mb_data['id'] = self.pubsub_item |
359 | 364 |
360 self.host.bridge.mbSend(self.pubsub_service, self.pubsub_node, mb_data, self.profile) | 365 self.host.bridge.mbSend(self.pubsub_service, self.pubsub_node, mb_data, self.profile) |
361 self.disp(u"Blog item published") | 366 self.disp(u"Blog item published") |
362 | 367 |
363 def getTmpSuff(self): | 368 def getTmpSuff(self): |
364 # we get current syntax to determine file extension | 369 # we get current syntax to determine file extension |
365 self.current_syntax = self.host.bridge.getParamA("Syntax", "Composition", "value", self.profile) | 370 if self.current_syntax is None: |
371 self.current_syntax = self.host.bridge.getParamA("Syntax", "Composition", "value", self.profile) | |
366 return SYNTAX_EXT.get(self.current_syntax, SYNTAX_EXT['']) | 372 return SYNTAX_EXT.get(self.current_syntax, SYNTAX_EXT['']) |
367 | 373 |
368 def getItemData(self, service, node, item): | 374 def getItemData(self, service, node, item): |
369 items = [item] if item is not None else [] | 375 items = [item] if item is not None else [] |
370 mb_data = self.host.bridge.mbGet(service, node, 1, items, {}, self.profile)[0][0] | 376 mb_data = self.host.bridge.mbGet(service, node, 1, items, {}, self.profile)[0][0] |
379 return content, mb_data, mb_data['id'] | 385 return content, mb_data, mb_data['id'] |
380 | 386 |
381 def start(self): | 387 def start(self): |
382 # if there are user defined extension, we use them | 388 # if there are user defined extension, we use them |
383 SYNTAX_EXT.update(config.getConfig(self.sat_conf, 'jp', CONF_SYNTAX_EXT, {})) | 389 SYNTAX_EXT.update(config.getConfig(self.sat_conf, 'jp', CONF_SYNTAX_EXT, {})) |
384 self.current_syntax = None | 390 self.current_syntax = self.args.syntax |
391 if self.current_syntax is not None: | |
392 try: | |
393 self.current_syntax = self.args.syntax = self.host.bridge.syntaxGet(self.current_syntax) | |
394 except Exception as e: | |
395 if "NotFound" in unicode(e): #Â FIXME: there is not good way to check bridge errors | |
396 self.parser.error(_(u"unknown syntax requested ({syntax})").format(syntax=self.args.syntax)) | |
397 else: | |
398 raise e | |
385 | 399 |
386 self.pubsub_service, self.pubsub_node, self.pubsub_item, content_file_path, content_file_obj, mb_data = self.getItemPath(self.args.item) | 400 self.pubsub_service, self.pubsub_node, self.pubsub_item, content_file_path, content_file_obj, mb_data = self.getItemPath(self.args.item) |
387 | 401 |
388 self.edit(content_file_path, content_file_obj, mb_data=mb_data) | 402 self.edit(content_file_path, content_file_obj, mb_data=mb_data) |
389 | 403 |