• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mobalazs / rotor-framework / 18919729013

29 Oct 2025 07:21PM UTC coverage: 85.379% (-0.1%) from 85.479%
18919729013

push

github

mobalazs
fix: update debug setting in bsconfig to enable debugging

1781 of 2086 relevant lines covered (85.38%)

1.16 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.67
/src/source/plugins/FontStylePlugin.bs
1
import "../base/BasePlugin.bs"
2

3
namespace Rotor
4

5
    ' =====================================================================
6
    ' FontStylePlugin - Rotor Framework plugin for font styling on Labels
7
    '
8
    ' Handles dynamic font styling on Label nodes with function evaluation
9
    ' and @-prefixed expression interpolation for dynamic font selection.
10
    ' Automatically updates font styles on widget lifecycle changes.
11
    '
12
    ' Key Features:
13
    '   - Applies font styles specifically to Label nodes
14
    '   - Evaluates function-based font style values
15
    '   - Interpolates @-prefixed expressions for dynamic font selection
16
    '   - Automatically updates font styles on widget lifecycle changes
17
    '
18
    ' Expression Syntax:
19
    '   @key.path - Resolves from widget.viewModelState
20
    '
21
    ' Note: Only affects widgets with nodeType = "Label"
22
    ' =====================================================================
23
    class FontStylePlugin extends Rotor.BasePlugin
24

25
        ' =============================================================
26
        ' MEMBER VARIABLES
27
        ' =============================================================
28

29
        ' Regex pattern for matching @-prefixed expressions
30
        ' Matches: @ followed by any characters except space, @, or comma
31
        configRegex = /(\@)([^\s\@\,]*)/i
32

33
        ' Regex pattern for extracting plugin key prefix (unused but kept for compatibility)
34
        pluginKeyRegex = /^[^\.]*/i
35

36
        ' =============================================================
37
        ' CONSTRUCTOR
38
        ' =============================================================
39

40
        ' ---------------------------------------------------------------------
41
        ' new - Initializes the FontStylePlugin instance
42
        '
43
        ' @param {string} key - Plugin identifier (default: "fontStyle")
44
        '
45
        sub new(key = "fontStyle" as string)
46
            super(key)
1✔
47
        end sub
48

49
        ' =============================================================
50
        ' LIFECYCLE HOOKS
51
        ' =============================================================
52

53
        hooks = {
54
            ' ---------------------------------------------------------------------
55
            ' beforeMount - Sets font style when widget is mounted
56
            '
57
            ' Evaluates and applies font style after Label widget creation.
58
            '
59
            ' @param {object} scope - Plugin instance (m)
60
            ' @param {object} widget - Widget being mounted
61
            '
62
            beforeMount: sub(scope as object, widget as object)
63
                scope.setFontAttribute(widget)
1✔
64
            end sub,
65

66
            ' ---------------------------------------------------------------------
67
            ' beforeUpdate - Updates font style when widget config changes
68
            '
69
            ' Re-evaluates and applies font style when fontStyle property changes.
70
            '
71
            ' @param {object} scope - Plugin instance (m)
72
            ' @param {object} widget - Widget being updated
73
            ' @param {dynamic} newValue - New font style configuration
74
            ' @param {dynamic} oldValue - Previous font style configuration
75
            '
76
            beforeUpdate: sub(scope as object, widget as object, newValue, oldValue)
77
                widget[scope.key] = newValue ?? ""
1✔
78
                scope.setFontAttribute(widget)
1✔
79
            end sub
80
        }
81

82
        ' =============================================================
83
        ' FONT STYLE PROCESSING
84
        ' =============================================================
85

86
        ' ---------------------------------------------------------------------
87
        ' setFontAttribute - Evaluates and applies font style to Label node
88
        '
89
        ' Processing logic:
90
        '   1. Checks if widget is a Label node (only Labels support font styles)
91
        '   2. Resolves font style value through function evaluation or interpolation
92
        '   3. Applies resolved font style to the node
93
        '
94
        ' Font Style Resolution:
95
        '   - Functions are executed in widget scope
96
        '   - @-prefixed strings are interpolated from viewModelState
97
        '   - Direct strings are used as-is
98
        '
99
        ' @param {object} widget - Widget instance
100
        '
101
        sub setFontAttribute(widget as object)
102
            ' Font styles only apply to Label nodes
103
            if widget.nodeType = "Label"
3✔
104
                value = widget[m.key]
1✔
105
                node = widget.node
1✔
106

107
                ' Step 1: Resolve function-based font style
108
                if Rotor.Utils.isFunction(value)
2✔
109
                    fontStyle = Rotor.Utils.callbackScoped(value, widget)
1✔
110

111
                ' Step 2: Process string interpolation
112
                else if Rotor.Utils.isString(value)
2✔
113
                    results = m.configRegex.MatchAll(value)
1✔
114

115
                    if results.Count() > 0 and Rotor.Utils.isString(value)
3✔
116
                        for each result in results
1✔
117
                            matchKey = result[2]                ' The key path after @
1✔
118
                            sourceTypeOperator = result[1]      ' The @ symbol
1✔
119

120
                            ' Determine source based on operator
121
                            if sourceTypeOperator = "@"
3✔
122
                                source = widget.viewModelState
1✔
123
                            else
×
124
                                source = widget
×
125
                            end if
126

127
                            if source <> invalid
3✔
128
                                ' Resolve font style from key path
129
                                assetValue = Rotor.Utils.getValueByKeyPath(source, matchKey)
1✔
130

131
                                ' Handle string vs non-string results
132
                                if Rotor.Utils.isString(assetValue)
2✔
133
                                    ' String interpolation - replace in original string
134
                                    replaceRegex = CreateObject("roRegex", sourceTypeOperator + matchKey, "ig")
×
135
                                    value = replaceRegex.ReplaceAll(value, assetValue)
×
136
                                else
137
                                    ' Non-string value - replace entire font style
3✔
138
                                    value = assetValue
1✔
139
                                    exit for
140
                                end if
141
                            end if
142
                        end for
143
                    end if
144

145
                    fontStyle = value
1✔
146

147
                ' Step 3: Direct value assignment
148
                else
3✔
149
                    fontStyle = value
1✔
150
                end if
151

152
                ' Apply font style to the Label node
153
                Rotor.Utils.setFontAttribute(node, fontStyle)
1✔
154
            end if
155
        end sub
156

157
    end class
158

159
end namespace
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc