Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibly use byu.hr.manage_apps as a module #3

Open
b1conrad opened this issue Jul 9, 2022 · 3 comments
Open

Possibly use byu.hr.manage_apps as a module #3

b1conrad opened this issue Jul 9, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@b1conrad
Copy link
Owner

b1conrad commented Jul 9, 2022

See issue #90 of that repo.

@b1conrad b1conrad added the enhancement New feature or request label Jul 9, 2022
@b1conrad
Copy link
Owner Author

Comparing boilerplate_rs.krl with byu.hr.manage_apps.krl, note that the makeInstalledRulesetAnApp rule of the latter could also do the channel management tasks of the former.

  1. Whenever a byname app is installed in a pico, we know that that pico already has the byu.hr.manage_apps ruleset
  2. Channels belong to the pico, not to the ruleset that creates them!

This would reduce the size of boilerplate code by 19 lines as those rules can be omitted from the boilerplate, along with the binding of the channel_tags name in line 9..

The above does not require usage as a module.

Furthermore, the convenience functions could be provided by the module, saving another 10 lines of boilerplate.

A call to these functions would have to pass along the RID, as apps are keyed by the RID. Assuming

    use module byu.hr.manage_apps alias app

the calls would look like:

      action_url = app:event_url(meta:rid,event_domain,"event_type")
      link_url = app:query_url(meta:rid,"name.html")
      home_url = app:main_url(meta:rid)

@b1conrad
Copy link
Owner Author

A generated boilerplate would look like

ruleset boilerplate_rs {
  meta {
    name "boilerplates"
    use module byu.hr.manage_apps alias app
    use module html.byu alias html
    shares boilerplate
  }
  global {
    event_domain = "boilerplate_rs"
    boilerplate = function(_headers){
      html:header("manage boilerplates","",null,null,_headers)
      + <<
<h1>Manage boilerplates</h1>
>>
      + html:footer()
    }
  }
}

@b1conrad
Copy link
Owner Author

Refactoring the HTML generating boilerplate, providing an html function that takes four arguments,

  1. the tab title string,
  2. a string of script, style, and other tags for inside the head,
  3. a string of the tags of the body,
  4. and the HTTP headers,

the boilerplate could be further simplified to these 16 lines, assuming a RID of hello-world, an app name of greetings, and a home page named hello:

ruleset hello-world {
  meta {
    name "greetings"
    use module byu.hr.manage_apps alias app
    shares hello
  }
  global {
    event_domain = "hello_world"
    hello = function(_headers){
      app:html("manage greetings", "",
<<
<h1>Manage greetings</h1>
>>, _headers)
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant