enjoysmath / BootstrapStudioToDjango

Convert a bootstrap studio file in a django (Jinja like) template.
GNU Affero General Public License v3.0
21 stars 4 forks source link

dj-ref Attributes are not converted #5

Open NiclasWil opened 2 months ago

NiclasWil commented 2 months ago

When I'm adding dj-ref Attributes to my HTML in Bootstrap Studio then theses references are never processed. They remain in HTML Tag as attributes Input File

<div class="ms-3">
    <h4 class="w-auto" dj-ref="conversationname">$$Conversation Name$$</h4>
    <p dj-ref="conversation.last_message">$$Nullam id dolor id nibh ultricies vehicula ut id elit. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus.$$</p>
</div>

Output File

<div class="ms-3">
      <h4 class="w-auto" dj-ref="conversationname">
              $$Conversation Name$$
       </h4>
       <p dj-ref="conversation.last_message">
              $$Nullam id dolor id nibh ultricies vehicula ut id elit. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus.$$
       </p>
</div>

All other tags i used so far instead of dj-ref are working fine. The problem seems to be TagConverter.convert() since replace_ref is never called

def convert(self):
      with open(self._filename, encoding='utf8') as htmlstream:
         self._bs = BeautifulSoup(htmlstream.read(), 'html.parser')

      self.remove_for_data()
      self.replace_include_tag()

      for tag in self.ENCLOSED_TAG:
         self.extend_tag(tag, before=True, after=True)

      for tag in self.REPLACE_TAG:
         self.extend_tag(tag)

      for tag in self.TAG_LINK:
         self.replace_links(tag)      

      content = self.replace_background_img(self.beautiful_soup.prettify())
      content = html.unescape(content)

      if self._loadStatic:
         content = f"{{% load static %}}\n\n{content}"

      self._bs = None

      return content

I could check the issue and create a PR for this. But not sure if this is the main issue (not tested yet)

NiclasWil commented 2 months ago

When I'm adding dj-ref Attributes to my HTML in Bootstrap Studio then theses references are never processed. They remain in HTML Tag as attributes Input File

<div class="ms-3">
    <h4 class="w-auto" dj-ref="conversationname">$$Conversation Name$$</h4>
    <p dj-ref="conversation.last_message">$$Nullam id dolor id nibh ultricies vehicula ut id elit. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus.$$</p>
</div>

Output File

<div class="ms-3">
      <h4 class="w-auto" dj-ref="conversationname">
              $$Conversation Name$$
       </h4>
       <p dj-ref="conversation.last_message">
              $$Nullam id dolor id nibh ultricies vehicula ut id elit. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus.$$
       </p>
</div>

All other tags i used so far instead of dj-ref are working fine. The problem seems to be TagConverter.convert() since replace_ref is never called

def convert(self):
      with open(self._filename, encoding='utf8') as htmlstream:
         self._bs = BeautifulSoup(htmlstream.read(), 'html.parser')

      self.remove_for_data()
      self.replace_include_tag()

      for tag in self.ENCLOSED_TAG:
         self.extend_tag(tag, before=True, after=True)

      for tag in self.REPLACE_TAG:
         self.extend_tag(tag)

      for tag in self.TAG_LINK:
         self.replace_links(tag)      

      content = self.replace_background_img(self.beautiful_soup.prettify())
      content = html.unescape(content)

      if self._loadStatic:
         content = f"{{% load static %}}\n\n{content}"

      self._bs = None

      return content

I could check the issue and create a PR for this. But not sure if this is the main issue (not tested yet)

def convert(self):
      with open(self._filename, encoding='utf8') as htmlstream:
         self._bs = BeautifulSoup(htmlstream.read(), 'html.parser')

      self.remove_for_data()
      self.replace_include_tag()
      ###I expect this line to be the solution
      self.replace_ref()

      for tag in self.ENCLOSED_TAG:
         self.extend_tag(tag, before=True, after=True)

      for tag in self.REPLACE_TAG:
         self.extend_tag(tag)

      for tag in self.TAG_LINK:
         self.replace_links(tag)      

      content = self.replace_background_img(self.beautiful_soup.prettify())
      content = html.unescape(content)

      if self._loadStatic:
         content = f"{{% load static %}}\n\n{content}"

      self._bs = None

      return content

But I'm not used to qork with QT and able to test

enjoysmath commented 2 months ago

I see your bug post, I will fix it maybe in a few days. Will post back here. Unless you want to fix it ? It's simple Python / Pyqt5 code.

NiclasWil commented 2 months ago

I added the line of Code i think would fix this bug. But I'm not able to test it properly. When i use pyinstaller to create a exe File the Path from BSS is not taken as Parameter. Seems to be an issue how i used pyinstaller because the python console is launching in background.

If i want to test manually I'm not able to instantiate the classes correctly since there are QT ExportMapper Objects needed for Fileconverter ect.

So i think I'm not used to QT enough yet to Test. Even if i create a batch that is calling bss_to_django.py from Bootstrap Studio something goes wrong that i can't figure out. So maybe you could provider me some Details how to test or you fix it, whenever there is time.

But great Tool so far helps a lot to migrate to django 😀