primrose 0.0.1 → 0.0.3

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: 5bb209d0d9da846bc7696fa3e0ee9b5aaac7ae0e9ea17d1347d521a8c262c9be
4
+ data.tar.gz: 6451b8fa8a5d3747c1e39279021958069eaaf2acc783aea9d760a0fce19fcef5
5
5
  SHA512:
6
- metadata.gz: dd085723441f9d29c8713a20f9bb3767771c0e26d3377e6c360bdd0407902446d88462a4940e73c984d09e4aa6718903d3d4fdeb2ccb392a91a6d4c31df3b444
7
- data.tar.gz: f124f56efebe490b8cab7d368f3187ffcff27ce80fba1030579131eb2097c18108ea7a9448fdfbc618c99c50877bb5a7d92f78a65eae008edbf39dc03f385573
6
+ metadata.gz: 6f801a9e52a670739c10aefce57b9b8566fca1c91b8ae038b1b3f5707948da270d37e95fbfaecdbb19409aa1e9801bff62142d779e3782ba9a841fcc60dacb2f
7
+ data.tar.gz: 6741bf29d095cef43d8610c3c6b2e9a607171d1ed6b324b7606c4a48e43ba7b62bc8e39f73564e33d73e76632f094179e914f1cecd57fae1b9cbb3cf6a2873e4
@@ -3,6 +3,18 @@ require_relative '../prim'
3
3
  module Primrose
4
4
  module Components
5
5
  class Button < Rose
6
+
7
+ TEMPLATE = <<~ERB
8
+ <button
9
+ onclick="<%= @action %>"
10
+ class="<%= @style %>"
11
+ <%= 'disabled' if @disabled %>
12
+ <%= 'loading' if @loading %>
13
+ >
14
+ <%= @label %>
15
+ </button>
16
+ ERB
17
+
6
18
  def initialize(label:, action:, style: nil, disabled: false, loading: false)
7
19
  @label = label
8
20
  @action = action
@@ -13,7 +25,7 @@ module Primrose
13
25
  end
14
26
 
15
27
  def render
16
- Prim.render('templates/components/button.prim.erb', self)
28
+ Prim.render(TEMPLATE, self)
17
29
  end
18
30
 
19
31
  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)
@@ -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)
@@ -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
@@ -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.3"
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.3
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: []
@@ -43,7 +43,7 @@ files:
43
43
  - lib/primrose/rose.rb
44
44
  - lib/primrose/router.rb
45
45
  - lib/primrose/store.rb
46
- - lib/primrose/utils/deep_clone.rb
46
+ - lib/primrose/utils/utils.rb
47
47
  - lib/primrose/version.rb
48
48
  homepage: https://github.com/mmatongo/primrose.rb
49
49
  licenses:
File without changes