Tags:
create new tag
, view all tags

Feature Proposals » VAR{...boolean="on"...} and ISTRUE{...}

Summary

Current State: Developer: Reason: Date: Concerns By: Bug Tracking: Proposed For:
AcceptedProposal HideyoImazu AcceptedBy7DayFeedbackPeriod 2014-05-20     KampalaRelease

Edit Form

TopicSummary:
CurrentState:
CommittedDeveloper:
ReasonForDecision:
DateOfCommitment:   Format: YYYY-MM-DD
ConcernRaisedBy:
BugTracking:
OutstandingIssues:
RelatedTopics:
InterestedParties:
ProposedFor:
TWikiContributors:
 

Motivation

There are cases where you want to determine if a preference variable is true or not for sure and safely.

Determining whether a preference is true or not is tricky. You can check if %FOO_ENABLE% is "on" or not by %IF{"$'FOO_ENABLE' = 'on'" ...}%. But ...

  • A user may put extra space after "* Set FOO_ENABLE = on", which sets "on " rather than "on" to FOO_NEABLE, in which case the condition "$'FOO_ENABLE' = 'on'" isn't met
  • A user may set "1" rather than "on" meaning true

Description and Documentation

A new parameter boolean will be introduced to the VAR variable. The parameter's value is evaluated by TWiki::isTrue(). If it's true, the Boolean mode is turned on. In the Boolean mode, the specified variable's value is handed to TWiki::isTrue(), whose result becomes the result of the %VAR{...}%. TWiki::isTrue() returning either 0 or 1, %VAR{...}% in the Boolean mode results in 0 or 1.

For example, if FOO_ENABLE is set to "off", %VAR{"FOO_ENABLE" boolean="on"}% will be expanded to 0.

%VAR{...boolean="on"...}% is rather verbose considering it will be used often. So a new variable %ISTRUE{...}% will be introduced as a shorthand of %VAR{...boolean="on"}%. %ISTRUE{FOO_ENABLE}% is equivalent to %VAR{"FOO_ENABLE" boolean="on"}%.

There might be cases where you want to specify true and false value. In that case, you will specify false and true values separated by comma.

Examples

%VAR{"FOO_ENABLE" boolean="false,true"}% will be expanded either false or true depending on the value of %FOO_DISABLED%. %ISTRUE{"FOO_ENABLE" boolean="false,true"}% will also work but the former looks better.

%ISTRUE{...}% will be handy in %IF{...}%. e.g. %IF{"%ISTRUE{FOO_ENABLE}%" then="..." else="..."}%.

Impact

Implementation

-- Contributors: Hideyo Imazu - 2014-05-20

Discussion

Looks good!

-- Peter Thoeny - 2014-05-20

Edit | Attach | Watch | Print version | History: r6 < r5 < r4 < r3 < r2 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r6 - 2014-07-03 - HideyoImazu
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.