primrose 0.0.1 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7bd154f7df76d53c3db2057c499b67edf417e621e0ff44c537382e9c78d946f6
4
- data.tar.gz: b1c996a5c456ca5f0407189656d99352918812559139ab2a9b35a82b44ffbab3
3
+ metadata.gz: a05873db52a828030b1bc392f0604de6da140fcf57f35eedfb64afc2aa6f2818
4
+ data.tar.gz: d2ee9d7796df7bc02dc9b7ff186d07a8f7f1db1c5abc14029469049117f4a7cc
5
5
  SHA512:
6
- metadata.gz: dd085723441f9d29c8713a20f9bb3767771c0e26d3377e6c360bdd0407902446d88462a4940e73c984d09e4aa6718903d3d4fdeb2ccb392a91a6d4c31df3b444
7
- data.tar.gz: f124f56efebe490b8cab7d368f3187ffcff27ce80fba1030579131eb2097c18108ea7a9448fdfbc618c99c50877bb5a7d92f78a65eae008edbf39dc03f385573
6
+ metadata.gz: 21c09149247fb8efe55916e56f1bb36767682af9bacbb3e008a67d59a44fbd7d6e6f37f061a4421bfe87fb95e2b4566c44384a28ac9c560ba4aa1d3e3ada4fcc
7
+ data.tar.gz: 4dc252ddb95bfe4df3087d245a33a1ba77539a6be09fd5cde3644e20483d4f2b416ad1431c76a11f75ba4f7cf083d0b4374ec212884d1bfea21115f3ed99393e
@@ -0,0 +1,20 @@
1
+ module Primrose
2
+ module Components
3
+ module Body
4
+ TEMPLATE = <<~ERB
5
+ <body>
6
+ <%= @content %>
7
+ </body>
8
+ ERB
9
+
10
+ def initialize(content:)
11
+ @content = content
12
+ super()
13
+ end
14
+
15
+ def render
16
+ Prim.render(TEMPLATE, self)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -3,6 +3,17 @@ require_relative '../prim'
3
3
  module Primrose
4
4
  module Components
5
5
  class Button < Rose
6
+ TEMPLATE = <<~ERB
7
+ <button
8
+ onclick="<%= @action %>"
9
+ class="<%= @style %>"
10
+ <%= 'disabled' if @disabled %>
11
+ <%= 'loading' if @loading %>
12
+ >
13
+ <%= @label %>
14
+ </button>
15
+ ERB
16
+
6
17
  def initialize(label:, action:, style: nil, disabled: false, loading: false)
7
18
  @label = label
8
19
  @action = action
@@ -13,7 +24,7 @@ module Primrose
13
24
  end
14
25
 
15
26
  def render
16
- Prim.render('templates/components/button.prim.erb', self)
27
+ Prim.render(TEMPLATE, self)
17
28
  end
18
29
 
19
30
  def set_disabled(value)
@@ -3,6 +3,14 @@ require_relative '../prim'
3
3
  module Primrose
4
4
  module Components
5
5
  class Checkbox < Rose
6
+ TEMPLATE = <<~ERB
7
+ <div class="checkbox">
8
+ <input type="checkbox" id="<%= @id %>" name="<%= @name %>" onchange="<%= @js %>" <%= 'checked="checked"' if @checked %> />
9
+ <label for="<%= @id %>"><%= @label %></label>
10
+ </div>
11
+ ERB
12
+
13
+
6
14
  def initialize(label:, checked: false, id: nil, name: nil, js: nil)
7
15
  @label = label
8
16
  @checked = checked
@@ -13,7 +21,7 @@ module Primrose
13
21
  end
14
22
 
15
23
  def render
16
- Prim.render('templates/partials/_checkbox.prim.erb', self)
24
+ Prim.render(TEMPLATE, self)
17
25
  end
18
26
 
19
27
  def set_checked(value)
@@ -0,0 +1,24 @@
1
+ module Primrose
2
+ module Components
3
+ class Form < Rose
4
+ TEMPLATE = <<~ERB
5
+ <form class="<%= @style_class %>" action="<%= @action %>" method="<%= @method %>">
6
+ <%= @elements.join("\n") %>
7
+ </form>
8
+ ERB
9
+
10
+ def initialize(elements:, method:, style_class: nil, action: nil, **opts)
11
+ @elements = elements
12
+ @options = opts
13
+ @style_class = style_class
14
+ @action = action
15
+ @method = method
16
+ super()
17
+ end
18
+
19
+ def render
20
+ Prim.render(TEMPLATE, self)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,29 @@
1
+ module Primrose
2
+ module Components
3
+ class GridLayout < Rose
4
+ TEMPLATE = <<~ERB
5
+ <div class="grid-layout <%= @style_class %>">
6
+ <% @rows.each do |row| %>
7
+ <div class="row">
8
+ <% row.each do |column| %>
9
+ <div class="column">
10
+ <%= column.render %>
11
+ </div>
12
+ <% end %>
13
+ </div>
14
+ <% end %>
15
+ </div>
16
+ ERB
17
+
18
+ def initialize(rows, columns, style_class: nil)
19
+ @style_class = style_class
20
+ @rows = rows
21
+ @columns = columns
22
+ end
23
+
24
+ def render
25
+ Prim.render(TEMPLATE, self)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,20 @@
1
+ module Primrose
2
+ module Components
3
+ class HiddenField < Rose
4
+ TEMPLATE = <<~ERB
5
+ <input type="hidden" name="<%= @name %>" value="<%= @value %>">
6
+ ERB
7
+
8
+ attr_reader :name, :value
9
+
10
+ def initialize(name:, value:)
11
+ @name = name
12
+ @value = value
13
+ end
14
+
15
+ def render
16
+ Prim.render(TEMPLATE, self)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,24 @@
1
+ module Primrose
2
+ module Components
3
+ class List < Rose
4
+ TEMPLATE = <<~ERB
5
+ <ul class="<%= @style_class %>">
6
+ <% @items.each do |item| %>
7
+ <li><%= item %></li>
8
+ <% end %>
9
+ </ul>
10
+ ERB
11
+
12
+ def initialize(items:, id: nil, style_class: nil)
13
+ @items = items
14
+ @id = id
15
+ @style_class = style_class
16
+ super()
17
+ end
18
+
19
+ def render
20
+ Prim.render(TEMPLATE, self)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,39 @@
1
+ require_relative '../prim'
2
+
3
+ module Primrose
4
+ module Components
5
+ class Modal < Rose
6
+ TEMPLATE = <<~ERB
7
+ <% if @is_open %>
8
+ <label for="modal-<%= @name %>"><%= @label %></label>
9
+ <div class="modal <%= @style_class %>">
10
+ <div class="modal-content">
11
+ <%= @content %>
12
+ </div>
13
+ </div>
14
+ <% end %>
15
+ ERB
16
+
17
+ def initialize(content:, is_open: false, name: nil, label: nil, style_class: nil)
18
+ @content = content
19
+ @is_open = is_open
20
+ @name = name
21
+ @label = label
22
+ @style_class = style_class
23
+ super()
24
+ end
25
+
26
+ def render
27
+ Prim.render(TEMPLATE, self)
28
+ end
29
+
30
+ def open
31
+ @is_open = true
32
+ end
33
+
34
+ def close
35
+ @is_open = false
36
+ end
37
+ end
38
+ end
39
+ end
@@ -3,9 +3,27 @@ require_relative '../prim'
3
3
  module Primrose
4
4
  module Components
5
5
  class Navbar < Rose
6
+ TEMPLATE = <<~ERB
7
+ <nav class="<%= 'sticky' if @sticky %>">
8
+ <%= @brand if @brand %>
9
+ <ul>
10
+ <% @links.each do |link| %>
11
+ <li class="<%= 'active' if link[:url] == @active_link %>">
12
+ <a href="<%= link[:url] %>"><%= link[:text] %></a>
13
+ <% if link[:dropdown] %>
14
+ <ul class="dropdown">
15
+ <% link[:dropdown].each do |dropdown_link| %>
16
+ <li><a href="<%= dropdown_link[:url] %>"><%= dropdown_link[:text] %></a></li>
17
+ <% end %>
18
+ </ul>
19
+ <% end %>
20
+ </li>
21
+ <% end %>
22
+ </ul>
23
+ </nav>
24
+ ERB
25
+
6
26
  def initialize(*args, links:, active_link: nil, sticky: false, brand: nil)
7
- # puts "Non-keyword args: #{args.inspect}"
8
- # puts "Initializing Navbar with #{links.inspect}, #{active_link}, #{sticky}, #{brand}"
9
27
  @links = links
10
28
  @active_link = active_link
11
29
  @sticky = sticky
@@ -14,7 +32,7 @@ module Primrose
14
32
  end
15
33
 
16
34
  def render
17
- Prim.render('templates/components/navbar.prim.erb', self)
35
+ Prim.render(TEMPLATE, self)
18
36
  end
19
37
 
20
38
  def set_active_link(new_active_link)
@@ -0,0 +1,35 @@
1
+ module Primrose
2
+ module Components
3
+ class Table < Rose
4
+ TEMPLATE = <<~ERB
5
+ <table>
6
+ <thead>
7
+ <tr>
8
+ <% @headers.each do |header| %>
9
+ <th><%= header %></th>
10
+ <% end %>
11
+ </tr>
12
+ </thead>
13
+ <tbody>
14
+ <% @rows.each do |row| %>
15
+ <tr>
16
+ <% row.each do |cell| %>
17
+ <td><%= cell %></td>
18
+ <% end %>
19
+ </tr>
20
+ <% end %>
21
+ </tbody>
22
+ </table>
23
+ ERB
24
+
25
+ def initialize(headers, rows)
26
+ @headers = headers
27
+ @rows = rows
28
+ end
29
+
30
+ def render
31
+ Prim.render(TEMPLATE, self)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -3,6 +3,21 @@ require_relative '../prim'
3
3
  module Primrose
4
4
  module Components
5
5
  class TextField < Rose
6
+ TEMPLATE = <<~ERB
7
+ <% if @label %>
8
+ <label for="textfield"><%= @label %></label>
9
+ <% end %>
10
+ <input type="text"
11
+ name="<%= @name %>"
12
+ placeholder="<%= @placeholder %>"
13
+ <% if @min_length %> minlength="<%= @min_length %>" <% end %>
14
+ <% if @max_length %> maxlength="<%= @max_length %>" <% end %>
15
+ <% if @read_only %> readonly <% end %>
16
+ <% if @default_value %> value="<%= @default_value %>" <% end %>
17
+ <% if @style_class %> class="<%= @style_class %>" <% end %>
18
+ >
19
+ ERB
20
+
6
21
  def initialize(placeholder:, name: nil, label: nil, min_length: nil, max_length: nil, read_only: false, default_value: nil, style_class: nil)
7
22
  @placeholder = placeholder
8
23
  @name = name
@@ -16,7 +31,7 @@ module Primrose
16
31
  end
17
32
 
18
33
  def render
19
- Prim.render('templates/components/text_field.prim.erb', self)
34
+ Prim.render(TEMPLATE, self)
20
35
  end
21
36
  end
22
37
  end
@@ -2,6 +2,13 @@ require_relative 'components/button'
2
2
  require_relative 'components/navbar'
3
3
  require_relative 'components/text_field'
4
4
  require_relative 'components/checkbox'
5
+ require_relative 'components/modal'
6
+ require_relative 'components/table'
7
+ require_relative 'components/list'
8
+ require_relative 'components/grid_layout'
9
+ require_relative 'components/hidden_field'
10
+ require_relative 'components/form'
11
+
5
12
 
6
13
  module Primrose
7
14
  module Helpers
@@ -35,5 +42,30 @@ module Primrose
35
42
  def checkbox(label:, checked: false, **opts)
36
43
  component('Checkbox', label: label, checked: checked, **opts)
37
44
  end
45
+
46
+ # def modal(content:, is_open: false, name: nil, label: nil, style_class: nil)
47
+ # component('Modal', content: content, is_open: is_open, name: name, label: label, style_class: style_class)
48
+ # end
49
+
50
+ # def table(headers:, rows:, **opts)
51
+ # component('Table', headers: headers, rows: rows, **opts)
52
+ # end
53
+
54
+ def list(items:, **opts)
55
+ component('List', items: items, **opts)
56
+ end
57
+
58
+ # def grid_layout(rows:, columns:, **opts)
59
+ # component('GridLayout', rows: rows, columns: columns, **opts)
60
+ # end
61
+
62
+ def hidden_field(name:, value:, **opts)
63
+ puts "Creating hidden field with name #{name} and value #{value}"
64
+ component('HiddenField', name: name, value: value)
65
+ end
66
+
67
+ def form(elements:, method:, style_class: nil, action: nil, **opts, &block)
68
+ component('Form', elements: elements, method: method, style_class: style_class, action: action, **opts, &block)
69
+ end
38
70
  end
39
71
  end
@@ -1,4 +1,4 @@
1
- require_relative 'utils/deep_clone'
1
+ require_relative 'utils/utils'
2
2
 
3
3
  module Primrose
4
4
  class Observable
data/lib/primrose/prim.rb CHANGED
@@ -6,8 +6,8 @@ module Primrose
6
6
  @template_cache = {}
7
7
  @logger = Logger.new(STDOUT)
8
8
 
9
- def self.render(template_path, context)
10
- template = read_template(template_path)
9
+ def self.render(template, context)
10
+ # template = read_template(template_path)
11
11
  erb = ERB.new(template)
12
12
  rendered = erb.result(context.get_binding)
13
13
 
@@ -20,11 +20,11 @@ module Primrose
20
20
 
21
21
  private
22
22
 
23
- def self.read_template(template_path)
24
- @template_cache[template_path] ||= File.read(template_path)
25
- rescue => e
26
- @logger.error("Could not read template: #{e.message}")
27
- raise
28
- end
23
+ # def self.read_template(template_path)
24
+ # @template_cache[template_path] ||= File.read(template_path)
25
+ # rescue => e
26
+ # @logger.error("Could not read template: #{e.message}")
27
+ # raise
28
+ # end
29
29
  end
30
30
  end
data/lib/primrose/rose.rb CHANGED
@@ -46,43 +46,9 @@ module Primrose
46
46
  # Error Handling
47
47
  def handle_error(error)
48
48
  puts "An error occurred: #{error.message}"
49
- # Log to a file or send to monitoring service
50
- # You can add more specific logic here based on the type of error
51
49
  error.backtrace.each { |line| puts line }
52
50
  end
53
51
 
54
- # Setup Hook
55
- def setup
56
- # Placeholder for logic to run only once during the object's lifetime,
57
- # prior to the `initialize` lifecycle method
58
- end
59
-
60
- # Additional Lifecycle Hooks
61
- def before_mount
62
- # Placeholder for logic to run before the component is added to the DOM
63
- end
64
-
65
- def after_mount
66
- # Placeholder for logic to run after the component is added to the DOM
67
- end
68
-
69
- def before_unmount
70
- # Placeholder for logic to run before the component is removed from the DOM
71
- end
72
-
73
- def after_unmount
74
- # Placeholder for logic to run after the component is removed from the DOM
75
- end
76
-
77
- # Existing hooks
78
- def before_render
79
- # Placeholder for logic to run immediately before the render method
80
- end
81
-
82
- def after_render
83
- # Placeholder for logic to run immediately after the render method
84
- end
85
-
86
52
  def get_binding
87
53
  binding
88
54
  end
@@ -1,3 +1,3 @@
1
1
  module Primrose
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: primrose
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel M. Matongo
@@ -24,7 +24,7 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '4.0'
27
- description: A gem for observable data structures and components
27
+ description: Build reactive web applications with observable data structures and components
28
28
  email: mmatongo_@hotmail.com
29
29
  executables: []
30
30
  extensions: []
@@ -33,9 +33,16 @@ files:
33
33
  - LICENSE
34
34
  - README.md
35
35
  - lib/primrose.rb
36
+ - lib/primrose/components/body.rb
36
37
  - lib/primrose/components/button.rb
37
38
  - lib/primrose/components/checkbox.rb
39
+ - lib/primrose/components/form.rb
40
+ - lib/primrose/components/grid_layout.rb
41
+ - lib/primrose/components/hidden_field.rb
42
+ - lib/primrose/components/list.rb
43
+ - lib/primrose/components/modal.rb
38
44
  - lib/primrose/components/navbar.rb
45
+ - lib/primrose/components/table.rb
39
46
  - lib/primrose/components/text_field.rb
40
47
  - lib/primrose/helpers.rb
41
48
  - lib/primrose/observable.rb
@@ -43,7 +50,7 @@ files:
43
50
  - lib/primrose/rose.rb
44
51
  - lib/primrose/router.rb
45
52
  - lib/primrose/store.rb
46
- - lib/primrose/utils/deep_clone.rb
53
+ - lib/primrose/utils/utils.rb
47
54
  - lib/primrose/version.rb
48
55
  homepage: https://github.com/mmatongo/primrose.rb
49
56
  licenses:
File without changes