ldown 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/ext/ldown/ldown.c +82 -3
- data/lib/ldown/version.rb +1 -1
- data/sig/ldown.rbs +5 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b16097857ad45355117148b40b13c2f594ba18883d0d6f61926bc38ae3409794
|
|
4
|
+
data.tar.gz: 116a72ca01a4c26b29bc72b29f66da974e4cce9546b095f615d7021a9ef41b59
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d3e298e130508d1feafef5daa836a23d35e1947b2991b5f450bb206f58a88bc036bee2b419108ea2012bce3069bdd1a2529b7a01a1d39e39e2cded87a8d756e8
|
|
7
|
+
data.tar.gz: 5b995203db308ee2d8c315c0c7bee42478f19e221a9569df9137a32a431ce1f4eeb1fa2f96ceeb420496e6851f054f15213827c681095d7f4d3e3a35853504da
|
data/CHANGELOG.md
CHANGED
data/ext/ldown/ldown.c
CHANGED
|
@@ -693,6 +693,13 @@ rbl_cTerm_m_render (VALUE self, VALUE node)
|
|
|
693
693
|
return rendered;
|
|
694
694
|
}
|
|
695
695
|
|
|
696
|
+
/* const node */
|
|
697
|
+
|
|
698
|
+
static const rb_data_type_t rbl_cConstNode_type
|
|
699
|
+
= { .wrap_struct_name = "lowdown constant node",
|
|
700
|
+
.function = { .dfree = RUBY_TYPED_NEVER_FREE },
|
|
701
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY };
|
|
702
|
+
|
|
696
703
|
/* node */
|
|
697
704
|
|
|
698
705
|
static void
|
|
@@ -713,16 +720,83 @@ rbl_cNode_alloc (VALUE klass)
|
|
|
713
720
|
return rb_data_typed_object_wrap (rbl_cNode, NULL, &rbl_cNode_type);
|
|
714
721
|
}
|
|
715
722
|
|
|
723
|
+
static inline struct lowdown_node *
|
|
724
|
+
rbl_node_unwrap (VALUE self)
|
|
725
|
+
{
|
|
726
|
+
if (rb_typeddata_is_kind_of (self, &rbl_cNode_type))
|
|
727
|
+
return RTYPEDDATA_DATA (self);
|
|
728
|
+
|
|
729
|
+
else
|
|
730
|
+
return rb_check_typeddata (self, &rbl_cConstNode_type);
|
|
731
|
+
}
|
|
732
|
+
|
|
716
733
|
static VALUE
|
|
717
734
|
rbl_cNode_m_id (VALUE self)
|
|
718
735
|
{
|
|
719
|
-
struct lowdown_node *node =
|
|
736
|
+
struct lowdown_node *node = rbl_node_unwrap (self);
|
|
720
737
|
return RB_SIZE2NUM (node->id);
|
|
721
738
|
}
|
|
722
739
|
|
|
740
|
+
static VALUE
|
|
741
|
+
rbl_cNode_m_parent (VALUE self)
|
|
742
|
+
{
|
|
743
|
+
struct lowdown_node *node = rbl_node_unwrap (self);
|
|
744
|
+
struct lowdown_node *parent = node->parent;
|
|
745
|
+
return parent ? rb_data_typed_object_wrap (rbl_cNode, parent,
|
|
746
|
+
&rbl_cConstNode_type)
|
|
747
|
+
: RUBY_Qnil;
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
static VALUE
|
|
751
|
+
rbl_cNode_m_first_child (VALUE self)
|
|
752
|
+
{
|
|
753
|
+
struct lowdown_node *node = rbl_node_unwrap (self);
|
|
754
|
+
struct lowdown_nodeq children = node->children;
|
|
755
|
+
struct lowdown_node *child = TAILQ_FIRST (&children);
|
|
756
|
+
return child ? rb_data_typed_object_wrap (rbl_cNode, child,
|
|
757
|
+
&rbl_cConstNode_type)
|
|
758
|
+
: RUBY_Qnil;
|
|
759
|
+
}
|
|
760
|
+
static VALUE
|
|
761
|
+
rbl_cNode_m_last_child (VALUE self)
|
|
762
|
+
{
|
|
763
|
+
struct lowdown_node *node = rbl_node_unwrap (self);
|
|
764
|
+
struct lowdown_nodeq children = node->children;
|
|
765
|
+
struct lowdown_node *child = TAILQ_LAST (&children, lowdown_nodeq);
|
|
766
|
+
return child ? rb_data_typed_object_wrap (rbl_cNode, child,
|
|
767
|
+
&rbl_cConstNode_type)
|
|
768
|
+
: RUBY_Qnil;
|
|
769
|
+
}
|
|
770
|
+
static VALUE
|
|
771
|
+
rbl_cNode_m_each_child (VALUE self)
|
|
772
|
+
{
|
|
773
|
+
struct lowdown_node *node = rbl_node_unwrap (self);
|
|
774
|
+
struct lowdown_nodeq children = node->children;
|
|
775
|
+
struct lowdown_node *child;
|
|
776
|
+
TAILQ_FOREACH (child, &children, entries)
|
|
777
|
+
rb_yield (
|
|
778
|
+
rb_data_typed_object_wrap (rbl_cNode, child, &rbl_cConstNode_type));
|
|
779
|
+
|
|
780
|
+
return RUBY_Qnil;
|
|
781
|
+
}
|
|
782
|
+
static VALUE
|
|
783
|
+
rbl_cNode_m_reverse_each_child (VALUE self)
|
|
784
|
+
{
|
|
785
|
+
struct lowdown_node *node = rbl_node_unwrap (self);
|
|
786
|
+
struct lowdown_nodeq children = node->children;
|
|
787
|
+
struct lowdown_node *child;
|
|
788
|
+
TAILQ_FOREACH_REVERSE (child, &children, lowdown_nodeq, entries)
|
|
789
|
+
rb_yield (
|
|
790
|
+
rb_data_typed_object_wrap (rbl_cNode, child, &rbl_cConstNode_type));
|
|
791
|
+
|
|
792
|
+
return RUBY_Qnil;
|
|
793
|
+
}
|
|
794
|
+
|
|
723
795
|
static VALUE
|
|
724
796
|
rbl_cNode_m_tree (int argc, VALUE *argv, VALUE self)
|
|
725
797
|
{
|
|
798
|
+
struct lowdown_node *node_ptr = rbl_node_unwrap (self);
|
|
799
|
+
|
|
726
800
|
VALUE kwargs;
|
|
727
801
|
rb_scan_args (argc, argv, ":", &kwargs);
|
|
728
802
|
|
|
@@ -732,7 +806,6 @@ rbl_cNode_m_tree (int argc, VALUE *argv, VALUE self)
|
|
|
732
806
|
if (out == NULL)
|
|
733
807
|
rb_raise (rbl_eError, "failed to create buffer");
|
|
734
808
|
|
|
735
|
-
struct lowdown_node *node_ptr = RTYPEDDATA_DATA (self);
|
|
736
809
|
if (lowdown_tree_rndr (out, node_ptr, &opts) == 0)
|
|
737
810
|
rb_raise (rbl_eError, "failed to render into Term");
|
|
738
811
|
|
|
@@ -744,7 +817,7 @@ rbl_cNode_m_tree (int argc, VALUE *argv, VALUE self)
|
|
|
744
817
|
static VALUE
|
|
745
818
|
rbl_cNode_m_diff_from (VALUE self, VALUE old)
|
|
746
819
|
{
|
|
747
|
-
struct lowdown_node *new =
|
|
820
|
+
struct lowdown_node *new = rbl_node_unwrap (self);
|
|
748
821
|
struct lowdown_node *o = rb_check_typeddata (old, &rbl_cNode_type);
|
|
749
822
|
size_t max_id;
|
|
750
823
|
struct lowdown_node *node = lowdown_diff (
|
|
@@ -821,6 +894,12 @@ Init_ldown (void)
|
|
|
821
894
|
rbl_cNode = rb_define_class_under (rb_mLdown, "Node", rb_cObject);
|
|
822
895
|
rb_define_alloc_func (rbl_cNode, rbl_cNode_alloc);
|
|
823
896
|
rb_define_method (rbl_cNode, "id", rbl_cNode_m_id, 0);
|
|
897
|
+
rb_define_method (rbl_cNode, "parent", rbl_cNode_m_parent, 0);
|
|
898
|
+
rb_define_method (rbl_cNode, "first_child", rbl_cNode_m_first_child, 0);
|
|
899
|
+
rb_define_method (rbl_cNode, "last_child", rbl_cNode_m_last_child, 0);
|
|
900
|
+
rb_define_method (rbl_cNode, "each_child", rbl_cNode_m_each_child, 0);
|
|
901
|
+
rb_define_method (rbl_cNode, "reverse_each_child",
|
|
902
|
+
rbl_cNode_m_reverse_each_child, 0);
|
|
824
903
|
rb_define_method (rbl_cNode, "tree", rbl_cNode_m_tree, -1);
|
|
825
904
|
rb_define_method (rbl_cNode, "diff_from", rbl_cNode_m_diff_from, 1);
|
|
826
905
|
|
data/lib/ldown/version.rb
CHANGED
data/sig/ldown.rbs
CHANGED
|
@@ -126,6 +126,11 @@ module Ldown
|
|
|
126
126
|
|
|
127
127
|
class Node
|
|
128
128
|
def id: -> Integer
|
|
129
|
+
def parent: -> Node
|
|
130
|
+
def first_child: -> Node
|
|
131
|
+
def last_child: -> Node
|
|
132
|
+
def each_child: () { (Node) -> void } -> void
|
|
133
|
+
def reverse_each_child: () { (Node) -> void } -> void
|
|
129
134
|
def diff_from: (Ldown::Node) -> Ldown::Node
|
|
130
135
|
def tree: (
|
|
131
136
|
# feat:
|