Created
October 15, 2011 11:52
-
-
Save rsbohn/1289463 to your computer and use it in GitHub Desktop.
KRL Resources Experiment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 10/15/2011 Randall Bohn | |
| Here is an attempt to solve the problem of loading different resources for KRL applications. Start | |
| with 'RulesetA.krl', which will load a resource ruleset, which then loads the target application. | |
| I think this solution would work, but is it a good solution? Would you have to bootstrap every event, | |
| or just "pageview" events? | |
| A Ruby script to generate the resource loading rulesets from a template wouldn't be too hard to put | |
| together. A 'rake' file could generate the rulesets and upload them to KNS for you. | |
| I guess a lot depends on the application. If you load one page, then do a bunch of AJAX this solution | |
| may be what you need. YMMV. Feel free to use modify these files as needed. | |
| Discuss this idea https://convore.com/kynetx/app-environments-i-need-a-smarter-solution/ | |
| *** Need a license? Use WTFPL. http://www.codinghorror.com/blog/2007/04/pick-a-license-any-license.html |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ruleset GreenResources { | |
| meta { | |
| name "Green Team Resources" | |
| description "Resources for team GREEN. Loaded from the bootstrap RulesetA." | |
| author "Randall Bohn" | |
| use javascript resource "https://library.exampley.com/team_green.js" | |
| } | |
| dispatch {} | |
| global {} | |
| rule bootstrap { | |
| select when explicit event bootstrap | |
| pre { target = event:attr("target_application) } | |
| noop() | |
| always { | |
| raise explicit event begin | |
| for target | |
| with team = "green" | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ruleset RedResources { | |
| meta { | |
| name "Red Team Resources" | |
| description "Resources for team RED. Loaded from the bootstrap RulesetA." | |
| author "Randall Bohn" | |
| use javascript resource "https://library.exampley.com/team_red.js" | |
| } | |
| dispatch {} | |
| global {} | |
| rule bootstrap { | |
| select when explicit event bootstrap | |
| pre { target = event:attr("target_application") } | |
| noop() | |
| always { | |
| raise explicit event begin | |
| for target | |
| with team = "red" | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ruleset RulesetA { | |
| meta { | |
| name "Ruleset A: Bootstrap Application" | |
| description << | |
| Load appropriate resources, then launch the target application. | |
| Of course all the ruleset names here are made up. Actual rulesets have names like "a421x70". | |
| This is an attempt to solve the problem of loading different (javascript|css) | |
| resources. Each resource bundle is loaded from a (minimal) ruleset. | |
| The minimal rulesets then signal a 'begin' explicit event to the target | |
| application ruleset. The chain of explicit events is an attempt to ensure | |
| that the resources load before the target application. | |
| >> | |
| author "Randall Bohn" | |
| logging on | |
| } | |
| dispatch {} | |
| global { | |
| team_resources = {"red": "RedResources", "green": "GreenResources", "blue": "BlueResources"} | |
| } | |
| rule bootstrap { | |
| select when web pageview "^http://(red|green|blue).exampley.com" setting (team_color) | |
| noop() | |
| always { | |
| raise explicit event bootstrap | |
| for team_resources.pick(team_color) | |
| with target_application = "TargetApplication" | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ruleset TargetApplication { | |
| meta { | |
| name "Target Application" | |
| description "This ruleset uses the team specific resources loaded from RulesetA." | |
| author "Randall Bohn" | |
| } | |
| dispatch {} | |
| global {} | |
| rule zero { | |
| select when explicit event begin | |
| pre { team = event:attr("team") } | |
| notify("Target Application", "Team #{team} wins!") with sticky = true; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment