Skip to content

mhulse/delim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Delim

The <custom:rg:delim> RULE (a.k.a tag) parses a delimited string and returns an iterable %ArrayOfDataTypes object.

Each object has been assigned to the attribute item which you can access in each iteration of the tag's loop.


USAGE

RULE/tag

<custom:rg:get:pics> attributes:

  1. string: String to parse (required).
  2. parent: Parent delimiter; the default is a | (pipe).
  3. child: Optional child delimiter.
  4. limit: Limit the number of parsed items returned; the default is 0 (no limit).
  5. reverse: Use to reverse the direction of the loop; this attribute does not require a value.
  6. key: The loop key variable name; the default name is key.
  7. count: Local loop counter variable name; the default name is count.
  8. item: Local item object variable name; the default name is item.
  9. total: Local variable name for total number of parent items; the default name is total.
  10. obj: Local %ArrayOfDataTypes object variable name; the default name is obj.

API access

##class(custom.rg.Delim).parse() parameters:

  1. string: String to parse (required).
  2. parent: Parent delimiter; the default is a | (pipe).
  3. child: Optional child delimiter.
  4. limit: Limit the number of parsed items returned; the default is 0 (no limit).

Returns: Parsed string as iterable %ArrayOfDataTypes object(s).


DEMO & EXAMPLES

Check out delim.csp (and here's the HTML output).


INSTALLATION

Of course, this goes without saying, but never install "stranger" code on your production system. Always use your test server to play!

With that said, there's a couple ways (that I can think of) to install this code:

Class copy/paste:

  1. "File" >> "New..." and choose "Caché Class Definition" from the "General" tab.
  2. Type "custom.rg" as the "package name".
  3. Type "Delim" as the "class name".
  4. Copy/paste the RAW contents of custom.rg.Delim.cls into this new file.
  5. Save and compile.

RULE copy/paste:

  1. "File" >> "New..." and choose "Caché Server Page" from the "CSP File" tab.
  2. Copy/paste the RAW contents of custom.rg.DelimRule.csr into this new file.
  3. Save this file as custom.rg.DelimRule.csr to the "CSP Files" >> /csp/cms/customrules package/folder/location.
  4. Compile.

RULE/class import local:

  1. Download and unzip this repo to your local machine.
  2. Open Studio.
  3. Change to the CMS namespace.
  4. "Tools" >> "Import Local...".
  5. Import custom.rg.DelimRule.csr and custom.rg.Delim.xml and check the compile box.

NOTES

Non-DTI customers should remove these lines from custom.rg.DelimRule.csr:

  1. Remove dt.common.page.Rule, from:

    <csr:class super="dt.common.page.Rule, %CSP.RuleBlock" />
    
  2. <script language="cache" runat="compiler">
    	do ##this.RenderDTStartTag()
    </script>
    
  3. <script language="cache" runat="compiler">
    	do ##this.RenderDTEndTag()
    </script>
    

DISCUSSION(S)


CHANGELOG

  • v2.0.1
    • 2013/06/27
      • Updated/normalized docblocks.
      • Changed a few argument names.
      • Cleaned up code.
      • Added a limit attribute/argument.
      • Fixed a few logic errors.
      • Explored my options for limiting/reversing/forwarding items and loops; not enough time to finalize code and will have to revisit.
  • v2.0.0:
    • 2013/06/27
      • Renamed custom.rg.Delim.csr to custom.rg.DelimRule.csr and updated all references to the old name.
    • 2013/06/26
      • Second push to GitHub.
      • Changed a bunch of stuff. :)
  • Pre-v2.0.0
    • It's the first commit.

LEGAL

Copyright © 2013 Micky Hulse

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with the License. You may obtain a copy of the License in the LICENSE file, or at:

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

About

Caché RULE & class used to parse delimited strings.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published