flora 0.7.0 → 0.8.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c1025da710c673e347a8e739d8d378b986386040ec9bdbe97e92ea5639d4a792
4
- data.tar.gz: 5aa256a0a55e2b4d345af8e63e6cb19f3627f723d24706091505f54d58bdafb0
3
+ metadata.gz: 0eeada6a7e97d9c1dded199028b8dac045682a23beef3481d219abecbbc07e2e
4
+ data.tar.gz: b892ba7503c36ec84ef5ae621b6029206def27c2e1d920314ac89793dedf0cbb
5
5
  SHA512:
6
- metadata.gz: b261bf5ab0e0d8c5203de5950792d5f272a7a7fb7da9055ea06a543018387534d7964f6d5dfc4550ed0cbcb6e529240176466c66f720d62445adfd09d87fb168
7
- data.tar.gz: e275dad3c3090f5aa53a5df129ea0fc3f2a3921ea3c4a35bf335764ae34c902cb3a07f4987dd8f8163f7f02654ad94c922d521a8f515c268293fbd2827afcc38
6
+ metadata.gz: 363719a84dfa9e6041a1db5e9ddcdec99218e30fb8c2c86b3b9b83a9a971cab3efb70a564a215b6263c6168d14a329fe34efb50746039f5fc206454cebe7ab21
7
+ data.tar.gz: cef5b21e8a2cea97cf180b5ca3e4d49e79aad9428ee6bd8b3bb8981e15674860f2223bb848386f9a133b97e6a4737f974ac8e520bd2161d4d350a83e38e7a09f
data/README.md CHANGED
@@ -26,6 +26,33 @@ end
26
26
 
27
27
  Install everything with `bundle install`, and then run `bundle exec flora serve` and open up http://localhost:3000!
28
28
 
29
+ ## Lilac
30
+
31
+ Lilac is Flora's DSL for writing HTML. Tags are just methods named the same as the tag, and children of tags are put inside blocks.
32
+
33
+ Looking for a way to make reusable components? Write a function! For example:
34
+
35
+ ```ruby
36
+ # lib/cool_title.rb
37
+ class CoolTitle
38
+
39
+ def self.render(text)
40
+ div(class: 'title') do
41
+ h1 do
42
+ text
43
+ end
44
+ end
45
+ end
46
+
47
+ end
48
+
49
+ # index.rb
50
+ html do
51
+ body do
52
+ CoolTitle.render('My blog')
53
+ end
54
+ end
55
+ ```
29
56
 
30
57
  ## The Flora way
31
58
 
data/lib/flora/app.rb CHANGED
@@ -50,7 +50,7 @@ class Flora::App
50
50
  end
51
51
 
52
52
  def call(env)
53
- @flora.reload_blueprint
53
+ @flora.reload_project
54
54
 
55
55
  @app.call(env)
56
56
  end
@@ -1,4 +1,4 @@
1
- module Flora::Project::Blueprint::Html
1
+ module Flora::Lilac
2
2
 
3
3
  TAGS = %i[
4
4
  a abbr address area article aside audio
@@ -10,14 +10,14 @@ module Flora::Project::Blueprint::Html
10
10
  h1 h2 h3 h4 h5 h6 head header hr html i iframe img input ins
11
11
  kbd keygen
12
12
  label legend li link
13
- main map mark menu meter
13
+ main map mark menu meta meter
14
14
  nav
15
15
  object ol optgroup option output
16
16
  p param pre progress
17
17
  q
18
18
  rp rt ruby
19
- s samp section select small source span strong sub summary sup
20
- table tbody td textarea tfoot th thead time tr track
19
+ s samp script section select small source span strong style sub summary sup
20
+ table tbody td textarea title tfoot th thead time tr track
21
21
  u ul
22
22
  var video
23
23
  wbr
@@ -17,8 +17,13 @@ class Flora::Plugins::Blog::Post
17
17
  end
18
18
 
19
19
 
20
+ def date
21
+ @frontmatter['date']
22
+ end
23
+
24
+
20
25
  def method_missing(name, ...)
21
- return @frontmatter[name] if @frontmatter[name]
26
+ return @frontmatter[name.to_s] if @frontmatter[name.to_s]
22
27
 
23
28
  super(name, ...)
24
29
  end
@@ -32,7 +37,7 @@ class Flora::Plugins::Blog::Post
32
37
  return {} unless page_data.start_with?('---')
33
38
  /(?<=---\n)(?<yaml>.*)(?=---\n)/m =~ @page.read
34
39
 
35
- YAML.load(yaml)
40
+ YAML.load(yaml, permitted_classes: [Date])
36
41
  end
37
42
 
38
43
  end
@@ -1,9 +1,31 @@
1
1
  module Flora::Plugins::Blog
2
2
 
3
+ class BlogPost < Flora::Project::Blueprint::Markdown
4
+
5
+ def self.recognize(file, config)
6
+ file.fnmatch?('posts/*.md')
7
+ end
8
+
9
+
10
+ def initialize(file, project)
11
+ super(file, project)
12
+
13
+ @post = Post.new(file, project.dir)
14
+ end
15
+
16
+
17
+ private
18
+
19
+ def render_tree
20
+ end
21
+
22
+ end
23
+
24
+
3
25
  module ProjectMethods
4
26
 
5
27
  def posts
6
- @dir.glob('posts/**').map { Post.new(it, @dir) }
28
+ @dir.glob('posts/**.md').map { Post.new(it, @dir) }.sort_by(&:date).reverse
7
29
  end
8
30
 
9
31
  end
@@ -10,9 +10,9 @@ class Flora::Project::Blueprint::Markdown < Flora::Project::Blueprint
10
10
 
11
11
  private
12
12
 
13
- def render_tree
13
+ def render_lilac
14
14
  silence_warnings do
15
- raw_html(Kramdown::Document.new(@file.read).to_html)
15
+ raw_html(Kramdown::Document.new(skipping_frontmatter(@file.read), input: 'GFM').to_html)
16
16
  end
17
17
  end
18
18
 
@@ -25,4 +25,10 @@ class Flora::Project::Blueprint::Markdown < Flora::Project::Blueprint
25
25
  $VERBOSE = old_verbose
26
26
  end
27
27
 
28
+
29
+ # TODO: Maybe just make frontmatter fully supported by Markdown?
30
+ def skipping_frontmatter(str)
31
+ str.gsub(/---\n(.*)---\n/m, '')
32
+ end
33
+
28
34
  end
@@ -1,5 +1,5 @@
1
- # A Blueprint that includes Nestable is something that can best nested into
2
- # Flora's HTML DSL layouts.
1
+ # A Blueprint that includes Nestable is something that can be nested into a
2
+ # Lilac-based layout.
3
3
  module Flora::Project::Blueprint::Nestable
4
4
 
5
5
  def render
@@ -8,10 +8,10 @@ module Flora::Project::Blueprint::Nestable
8
8
 
9
9
  layouts = find_layouts
10
10
  tree = render_internal(layouts, layouts.size) do
11
- render_tree
11
+ render_lilac
12
12
  end
13
13
 
14
- Flora::Project::Blueprint::Html.to_html(tree)
14
+ Flora::Lilac.to_html(tree)
15
15
  end
16
16
 
17
17
 
@@ -25,6 +25,11 @@ module Flora::Project::Blueprint::Nestable
25
25
  layouts << maybe_layout if maybe_layout.exist?
26
26
  end
27
27
 
28
+ # Ascend doesn't go to the top level directory.
29
+ # TODO: Make this code less brittle.
30
+ maybe_layout = Pathname.new('./_layout.rb')
31
+ layouts << maybe_layout if maybe_layout.exist?
32
+
28
33
  layouts
29
34
  end
30
35
 
@@ -10,7 +10,7 @@ class Flora::Project::Blueprint::RubyHtml < Flora::Project::Blueprint
10
10
 
11
11
  private
12
12
 
13
- def render_tree
13
+ def render_lilac
14
14
  instance_eval(@file.read)
15
15
  end
16
16
 
data/lib/flora/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Flora
2
- VERSION = '0.7.0'
2
+ VERSION = '0.8.0'
3
3
  end
data/lib/flora.rb CHANGED
@@ -10,11 +10,11 @@ class Flora
10
10
  def initialize(dir)
11
11
  dir = Pathname.new(dir)
12
12
 
13
- # Inject HTML helpers into Kernel so they're available everywhere. Just
14
- # instance_eval isn't enough because they'll be missing in lib/ code.
13
+ # Inject Lilac into the Kernel so it's available everywhere. Just
14
+ # instance_eval isn't enough because it'll be missing in lib/ code.
15
15
  #
16
16
  # TODO: is there a less disruptive way to do this?
17
- Kernel.prepend(Flora::Project::Blueprint::Html)
17
+ Kernel.prepend(Flora::Lilac)
18
18
 
19
19
  # The classes that are pluggable get their own instances to avoid conflicting
20
20
  # with other instances of Flora in the same process. This is mostly for the
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flora
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Vladimiroff
@@ -65,6 +65,20 @@ dependencies:
65
65
  - - ">="
66
66
  - !ruby/object:Gem::Version
67
67
  version: '0'
68
+ - !ruby/object:Gem::Dependency
69
+ name: kramdown-parser-gfm
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ type: :runtime
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
68
82
  - !ruby/object:Gem::Dependency
69
83
  name: rack
70
84
  requirement: !ruby/object:Gem::Requirement
@@ -109,13 +123,13 @@ files:
109
123
  - lib/flora/cli.rb
110
124
  - lib/flora/config.rb
111
125
  - lib/flora/factory.rb
126
+ - lib/flora/lilac.rb
112
127
  - lib/flora/plugins/blog.rb
113
128
  - lib/flora/plugins/blog/post.rb
114
129
  - lib/flora/plugins/redirector.rb
115
130
  - lib/flora/plugins/static_files.rb
116
131
  - lib/flora/project.rb
117
132
  - lib/flora/project/blueprint.rb
118
- - lib/flora/project/blueprint/html.rb
119
133
  - lib/flora/project/blueprint/markdown.rb
120
134
  - lib/flora/project/blueprint/nestable.rb
121
135
  - lib/flora/project/blueprint/ruby_html.rb