foxpage 0.2.1 → 0.2.2

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: 80a1fdb0c07dcf54fcca8c9fa2e3d6e2b7b1567edb663d298b1dd97ab33d37f8
4
- data.tar.gz: 6b3c0c52f6146f0124e616a07cd941e7845543d813f5aadbbccc70d58c41bf7e
3
+ metadata.gz: 8037f2e78043aa067766f40fff0d279c4c6b94e205656d3897ea4fa820120928
4
+ data.tar.gz: c38fa73ab21a672d01ac81de9131e7855805cadbde981a46a97fc5b891f6d8c8
5
5
  SHA512:
6
- metadata.gz: c745470d17e8ab8b47a9f2c24aab465129fafa219adb42d50a39b10529b71f9d78011d0abc32888038f7a5ddd251efd7f63b99dee83f974933f66b96bdec0f9b
7
- data.tar.gz: 91dc44b03e5ba5b431d24d3f462d657ca2b6a306336a64224625ddd488cdc0abbf5c8ff03b4a2ce56a909b9b3c4fa2ef597a85df924d05fad447183c5341364c
6
+ metadata.gz: d100781bd93a0f7c5900f8f8a0fc062a0d4ff42459af50d8b36684b089ff68774a739458e492824079bf8bbd108bedf88d1d2b3aabe8118480db89ef3c7dd60e
7
+ data.tar.gz: 938431d7c2787a57c3f31187b6fafc0259f6bde44e8e4e8216af2255c7ca12c2610304fbdf8648b9ed4198b6eb03c5228224994b85068f97725fd67fde1082fe
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- foxpage (0.2.1)
4
+ foxpage (0.2.2)
5
5
  haml (~> 5.1)
6
6
  listen (~> 3.1)
7
7
  sassc (~> 2.0)
@@ -22,10 +22,9 @@ GEM
22
22
  temple (>= 0.8.0)
23
23
  tilt
24
24
  jaro_winkler (1.5.2)
25
- listen (3.1.5)
26
- rb-fsevent (~> 0.9, >= 0.9.4)
27
- rb-inotify (~> 0.9, >= 0.9.7)
28
- ruby_dep (~> 1.2)
25
+ listen (3.2.0)
26
+ rb-fsevent (~> 0.10, >= 0.10.3)
27
+ rb-inotify (~> 0.9, >= 0.9.10)
29
28
  parallel (1.17.0)
30
29
  parser (2.6.3.0)
31
30
  ast (~> 2.4.0)
@@ -56,18 +55,17 @@ GEM
56
55
  ruby-progressbar (~> 1.7)
57
56
  unicode-display_width (>= 1.4.0, < 1.6)
58
57
  ruby-progressbar (1.10.1)
59
- ruby_dep (1.5.0)
60
58
  sassc (2.2.1)
61
59
  ffi (~> 1.9)
62
- sprockets (4.0.0.beta10)
60
+ sprockets (4.0.0)
63
61
  concurrent-ruby (~> 1.0)
64
62
  rack (> 1, < 3)
65
63
  temple (0.8.2)
66
64
  thor (0.20.3)
67
65
  tilt (2.0.10)
68
66
  unicode-display_width (1.5.0)
69
- webrick (1.4.2)
70
- zeitwerk (2.1.10)
67
+ webrick (1.5.0)
68
+ zeitwerk (2.2.1)
71
69
 
72
70
  PLATFORMS
73
71
  ruby
@@ -13,6 +13,7 @@ module FoxPage
13
13
  env = ::Sprockets::Environment.new(root)
14
14
  env.append_path("app/assets/stylesheets")
15
15
  env.append_path("app/assets/images")
16
+ env.append_path("app/assets/javascripts")
16
17
 
17
18
  manifest = ::Sprockets::Manifest.new(
18
19
  env, "./#{OUTPUT_DIRECTORY}/assets/.sprockets_manifest.json"
@@ -12,12 +12,7 @@ module FoxPage
12
12
  def build_pages
13
13
  app.routes.each do |path, route|
14
14
  if route.generate_all
15
- model = route.generate_all.camelize.constantize
16
-
17
- model.all.each do |item|
18
- target_path = format(path, id: item.id)
19
- build_single_page(target_path, route, id: item.id)
20
- end
15
+ build_all_the_pages(path, route)
21
16
  next
22
17
  end
23
18
 
@@ -25,6 +20,23 @@ module FoxPage
25
20
  end
26
21
  end
27
22
 
23
+ def build_all_the_pages(path, route)
24
+ enumerable =
25
+ if route.generate_all.is_a?(Symbol)
26
+ model = route.generate_all.camelize.constantize
27
+ model.all
28
+ else
29
+ route.generate_all.call
30
+ end
31
+
32
+ enumerable.each_with_index do |item, index|
33
+ id = (item.respond_to?(:id) && item.id) || index
34
+ # have page numbers start with 1
35
+ target_path = format(path, id: id == index ? id + 1 : id)
36
+ build_single_page(target_path, route, id: id)
37
+ end
38
+ end
39
+
28
40
  def build_single_page(target_path, route, params = {})
29
41
  if params.empty?
30
42
  params_log_str = ""
@@ -15,6 +15,8 @@ module FoxPage
15
15
  end
16
16
 
17
17
  # Instructs the site builder to generate pages for all records of `model`.
18
+ # model can be a symbol (which will use an actual FoxPage::Model), or a
19
+ # Proc returning an Enumerable.
18
20
  def self.generate_all(model)
19
21
  @__generate_all = model
20
22
  end
@@ -13,6 +13,10 @@ module FoxPage
13
13
  def stylesheet_link_tag(source, prepend: "")
14
14
  %(<link rel="stylesheet" href=#{asset_path(source, prepend: prepend).inspect} />)
15
15
  end
16
+
17
+ def javascript_include_tag(source, prepend: "")
18
+ %(<script language="JavaScript" src=#{asset_path(source, prepend: prepend).inspect}></script>)
19
+ end
16
20
  end
17
21
  end
18
22
  end
@@ -60,10 +60,13 @@ module FoxPage
60
60
  when :dir
61
61
  default_opts = { extension: :md }
62
62
  opts = default_opts.merge(@__storage_type_opts)
63
- files = Dir[app.root.join("data", data_name, "*.#{opts.fetch(:extension)}")]
63
+ base_data_dir = app.root.join("data", data_name)
64
+ files = Dir[File.join(base_data_dir, "**", "*.#{opts.fetch(:extension)}")]
64
65
 
65
66
  @__data = files.map do |fn|
66
- id = File.basename(fn, ".#{opts.fetch(:extension)}")
67
+ id = File.join(File.dirname(fn).sub(/\A#{base_data_dir}/, ""),
68
+ File.basename(fn, ".#{opts.fetch(:extension)}"))
69
+ .sub(/\A(?:#{File::SEPARATOR})/, "")
67
70
  content = IO.read(fn)
68
71
 
69
72
  front_matter = {}
@@ -39,31 +39,37 @@ module FoxPage
39
39
  controller = controller_for(base_name)
40
40
  base_path = "/#{path}"
41
41
 
42
- # show action needs some additional stuff to make it work
43
- # since we have to know all the ids beforehand
44
- if actions.delete :show
45
- method_name = :show
46
- validate_controller_method(controller, method_name)
47
- route_path = "#{base_path}/%<id>s"
42
+ # insert a route with id 0 as index if generate_all was specified, but without the /id in the path
43
+ if actions.find(:index)
44
+ validate_controller_method(controller, :index)
48
45
 
49
- routes[route_path] = make_target(
46
+ routes[base_path] = make_target(
50
47
  base_name: base_name,
51
48
  controller: controller,
52
- method_name: method_name,
53
- params: {},
54
- generate_all: controller.instance_variable_get(:@__generate_all_for)&.[](method_name)
49
+ method_name: :index,
50
+ params: { id: 0 },
51
+ generate_all: nil
55
52
  )
56
53
  end
57
54
 
58
55
  actions.each do |action|
59
56
  method_name = action
60
57
  validate_controller_method(controller, method_name)
58
+
59
+ generate_all = controller.instance_variable_get(:@__generate_all_for)&.[](method_name)
60
+
61
61
  route_path = method_name == :index ? base_path : "#{base_path}/#{method_name}"
62
+ if generate_all
63
+ # :show gets a pretty id, whereas :index (and others) get it prefixed with /page
64
+ route_path = method_name == :show ? "#{base_path}/%<id>s" : "#{route_path}/page/%<id>s"
65
+ end
62
66
 
63
- routes[route_path] = make_target(
67
+ routes[route_path] ||= make_target(
64
68
  base_name: base_name,
65
69
  controller: controller,
66
- method_name: method_name
70
+ method_name: method_name,
71
+ params: {},
72
+ generate_all: generate_all
67
73
  )
68
74
  end
69
75
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FoxPage
4
- VERSION = "0.2.1"
4
+ VERSION = "0.2.2"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foxpage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Georg Gadinger
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-01 00:00:00.000000000 Z
11
+ date: 2019-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor