hobby-pages 0.0.3 → 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
  SHA1:
3
- metadata.gz: 463049d724d82260a66dc52ae4ad9d8f4d8f32e4
4
- data.tar.gz: d6d67c9f4f053c4031d72810ee9c2651fd0d8ee0
3
+ metadata.gz: 6e6db678112c7d9a11a8281c4131e607e9b1d155
4
+ data.tar.gz: 6df58f7fa8122d8e7865af55536854282161292e
5
5
  SHA512:
6
- metadata.gz: 9b580ee8384a29b83a93c1b47745bf2adfd1b31a3ea94ed2d2346765785927b1edb8a328a6a4c3dad03545ce472d9f7b54c1539f44bf810f56574adfa9c1079c
7
- data.tar.gz: f04bf5352ef488ac0bfaf6c56c18b36f93798290ae6dd3afcaf82a51d9f974dd76ce4f9a1500a5018fbfe9bfc33d3944575bb7fbf958f26145b69a627b7f87db
6
+ metadata.gz: c836329640bebae055ba35dfb703333812b6bbbd9f95a06f097e2983066cc7fa017adab173affb548b336b4e7d741aa15c544802068f2de0fbbf991398642720
7
+ data.tar.gz: 9ae7499ce9b23776f3dbd712d64fe3b354b34e4ac0b75ea3bdd49595da8af17206ef423db4d839192d58d2a87cf54bad7bd21e4ab08e30051f452ee4e796dd18
data/hobby-pages.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |g|
2
2
  g.name = 'hobby-pages'
3
3
  g.files = `git ls-files`.split($/)
4
- g.version = '0.0.3'
4
+ g.version = '0.0.4'
5
5
  g.summary = 'A Hobby app to return a bunch of HTML pages from a directory.'
6
6
  g.authors = ['Anatoly Chernow']
7
7
 
data/lib/hobby/pages.rb CHANGED
@@ -46,6 +46,35 @@ module Hobby
46
46
  end
47
47
  end
48
48
 
49
+ def css_tag
50
+ @css_tag ||= if css
51
+ "<style>#{css}</style>"
52
+ else
53
+ ''
54
+ end
55
+ end
56
+
57
+ def js_tag
58
+ @js_tag ||= if js
59
+ "<script>#{js}</script>"
60
+ else
61
+ ''
62
+ end
63
+ end
64
+
65
+ def css
66
+ style_file = "#{directory}/css/pages/#{name}.sass"
67
+ if File.exist? style_file
68
+ sass_string = IO.read style_file
69
+ load_path = "#{directory}/css/pages/#{name}"
70
+ Sass::Engine.new(sass_string, load_paths: [load_path]).render
71
+ end
72
+ end
73
+
74
+ def js
75
+ directory.sprockets["pages/#{name}.js"]
76
+ end
77
+
49
78
  class Directory
50
79
  def initialize root
51
80
  @root = root
@@ -97,25 +126,13 @@ module Hobby
97
126
 
98
127
  script_file = "#{directory.to_s}/html/ruby/#{name}.rb"
99
128
  @script = IO.read script_file if File.exist? script_file
100
-
101
- style_file = "#{directory.to_s}/css/pages/#{name}.sass"
102
- if File.exist? style_file
103
- sass_string = IO.read style_file
104
- load_path = "#{directory.to_s}/css/pages/#{name}"
105
- css = Sass::Engine.new(sass_string, load_paths: [load_path]).render
106
- @css_tag = "<style id='for_page_#{name}'>#{css}</style>"
107
- end
108
-
109
- if js = directory.sprockets["pages/#{name}.js"]
110
- @js_tag = "<script id='js_for_page_#{name}'>#{js}</script>"
111
- end
112
129
  end
113
130
 
114
131
  def render app
115
132
  app.instance_eval @script if @script
116
133
 
117
134
  @layout.render app do
118
- "#{@css_tag}#{@js_tag}#{@template.render app}"
135
+ @template.render app
119
136
  end
120
137
  end
121
138
  end
@@ -0,0 +1,3 @@
1
+ require 'hobby/pages'
2
+
3
+ run Hobby::Pages.new '.'
@@ -5,6 +5,8 @@ html
5
5
  title= @head
6
6
  - else
7
7
  title Default layout
8
+ == css_tag
9
+ == js_tag
8
10
 
9
11
  body
10
12
  == yield
data/spec/main_spec.rb CHANGED
@@ -51,7 +51,7 @@ describe Hobby::Pages do
51
51
  response = @conn.get path: '/with-css'
52
52
  doc = Nokogiri.HTML response.body
53
53
 
54
- text = doc.at_css('style#for_page_with-css').text
54
+ text = doc.at_css('style').text
55
55
  expect(text).to eq "input {\n width: 100%; }\n"
56
56
  end
57
57
 
@@ -59,7 +59,7 @@ describe Hobby::Pages do
59
59
  response = @conn.get path: '/with-js'
60
60
  doc = Nokogiri.HTML response.body
61
61
 
62
- text = doc.at_css('script#js_for_page_with-js').text
62
+ text = doc.at_css('script').text
63
63
  expect(text).to eq <<~S
64
64
  (function() {
65
65
  alert('something');
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hobby-pages
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anatoly Chernow
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-21 00:00:00.000000000 Z
11
+ date: 2017-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hobby
@@ -104,6 +104,7 @@ files:
104
104
  - Gemfile
105
105
  - hobby-pages.gemspec
106
106
  - lib/hobby/pages.rb
107
+ - spec/dirs/main/config.ru
107
108
  - spec/dirs/main/css/pages/with-css.sass
108
109
  - spec/dirs/main/css/pages/with-css/width.sass
109
110
  - spec/dirs/main/html/layouts/default.slim