~dmbaturin/soupault

3 2

How to Access nav_path?

Details
Message ID
<3da1d831-0a52-da92-35c3-29b7d2ff85b1@aoirthoir.com>
DKIM signature
pass
Download raw message
I have tried several things to access the values in nav_path and am 
having no luck. It says it is a list of strings and i would like to 
traverse those strings.
Daniil Baturin
Details
Message ID
<33e58662-350a-a41b-643f-d0318472d07d@yandex.ru>
In-Reply-To
<3da1d831-0a52-da92-35c3-29b7d2ff85b1@aoirthoir.com> (view parent)
DKIM signature
pass
Download raw message
Sorry, I missed this question. Could you show an example of code that
doesn't work as expected?
Details
Message ID
<5196bdba-d619-313e-3448-c062754d32bd@aoirthoir.com>
In-Reply-To
<33e58662-350a-a41b-643f-d0318472d07d@yandex.ru> (view parent)
DKIM signature
pass
Download raw message
This code works:

text    = 'DELETED EVERYTHING'
html    = HTML.create_element('h1', text)
element = HTML.select_one(page, 'body')
HTML.replace_content(element, html)

This code does not work

text    = nav_path
html    = HTML.create_element('h1', text)
element = HTML.select_one(page, 'body')
HTML.replace_content(element, html)

This code also does not work.

text    = nav_path[1]
html    = HTML.create_element('h1', text)
element = HTML.select_one(page, 'body')
HTML.replace_content(element, html)

I have  tried assigning nav_path to variables, tried  using it directly, 
tried doing a count, tried using it as an array item..  I am at a 
complete loss.
Details
Message ID
<315a49a3-59b1-19a0-a382-4268cc3802b9@aoirthoir.com>
In-Reply-To
<33e58662-350a-a41b-643f-d0318472d07d@yandex.ru> (view parent)
DKIM signature
pass
Download raw message
Alright I figured out what I was doing wrong here...

With nav_path it isnt until you get a couple layers deep before it even 
appears.. so the array is basically empty until then... here is how i 
tested.. a little cheating plugin that I now run on a test site with 
nothing else to see if i get values from my prototype plugins

results = '\nPAGE FILE: '..page_file..
           '\n   PLUGIN: '..config.widget..
           '\n  MESSAGE: '..config.message..'\n           '

local key, value = next(nav_path,nil)
while key do
   results    = results..'nav.'..key..' = "'..value..'"'
   results    = results..'\n           '
   key, value = next(nav_path,key)
end

Log.warning(results)

On this tree:

.
├── index.html
└── yes
     ├── index.html
     └── no
         ├── index.html
         └── maybe
             ├── index.html
             └── ok
                 ├── index.html
                 └── whynot
                     └── index.html

I get this results:

zed> soupault
[WARNING]
PAGE FILE: site/index.html
    PLUGIN: bla
   MESSAGE: oh shyt

[WARNING]
PAGE FILE: site/yes/index.html
    PLUGIN: bla
   MESSAGE: oh shyt

[WARNING]
PAGE FILE: site/yes/no/index.html
    PLUGIN: bla
   MESSAGE: oh shyt
            nav.1 = "yes"

[WARNING]
PAGE FILE: site/yes/no/maybe/index.html
    PLUGIN: bla
   MESSAGE: oh shyt
            nav.1 = "yes"
            nav.2 = "no"

[WARNING]
PAGE FILE: site/yes/no/maybe/ok/index.html
    PLUGIN: bla
   MESSAGE: oh shyt
            nav.1 = "yes"
            nav.2 = "no"
            nav.3 = "maybe"

[WARNING]
PAGE FILE: site/yes/no/maybe/ok/whynot/index.html
    PLUGIN: bla
   MESSAGE: oh shyt
            nav.4 = "ok"
            nav.1 = "yes"
            nav.2 = "no"
            nav.3 = "maybe"
Export thread (mbox)