rack-app-front_end 0.1.0 → 0.2.0

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: 66e2c7fe3be8727a7f5046ae0d7a5d0b9942d85b
4
- data.tar.gz: 1924cc9d774971c0cb4b5911313ccceac7d85866
3
+ metadata.gz: 701a95d72e72d60f77ca4fe30f49baa90160a845
4
+ data.tar.gz: 3d833a3e63180ccbd613f72af2c47fb6e6090946
5
5
  SHA512:
6
- metadata.gz: d4530e60a4cbed9c90fa39692d0253ee81c494a540a741436814b5fceef9bc3d649ba711fdc247f5a3267b9f7e6da4d4da8098478851276073fc207598d738c2
7
- data.tar.gz: 6df2bd31cbbccaae9019a101b5896262bcd3be1eb969302f29d0dfdafc707d7c6f8d13b251f0d6b6404bb17e043d8184c6d7b0a81662c2568acd730852010710
6
+ metadata.gz: 9b9bcaead7908d00bb8e7b03a24dfa29b51d31e19faf8aff0edefbcdc54c770148d95fe8b33b8232e438733dd117036da90d28a1e682437ae323d3821ecf674d
7
+ data.tar.gz: 8f652b17dac308c8eb44f54d2f8f92a474ad4dea341998f5e3a9cf941ae3147c3749c0c52b2cdfc728f3fac02e29154c4ab58897685738dd391c431c750dc1a1
data/README.md CHANGED
@@ -1,15 +1,13 @@
1
- # Rack::App::Mvc
1
+ # Rack::App::FrontEnd
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rack/app/front_end`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ This is an extend module for Rack::App to have FrontEnd framework extensions for the core app class
6
4
 
7
5
  ## Installation
8
6
 
9
7
  Add this line to your application's Gemfile:
10
8
 
11
9
  ```ruby
12
- gem 'rack-app-mvc'
10
+ gem 'rack-app-front_end'
13
11
  ```
14
12
 
15
13
  And then execute:
@@ -18,11 +16,23 @@ And then execute:
18
16
 
19
17
  Or install it yourself as:
20
18
 
21
- $ gem install rack-app-mvc
19
+ $ gem install rack-app-front_end
22
20
 
23
21
  ## Usage
24
22
 
25
- TODO: Write usage instructions here
23
+ ```ruby
24
+
25
+ class App < Rack::App
26
+
27
+ extend Rack::App::FrontEnd
28
+
29
+ mount_folder '/public'
30
+ mount_folder 'relative/folder/from/this'
31
+
32
+ end
33
+
34
+ ```
35
+
26
36
 
27
37
  ## Development
28
38
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
@@ -5,11 +5,10 @@ class Rack::App::FrontEnd::FolderMounter
5
5
  @app_class = app_class
6
6
  end
7
7
 
8
- def mount(folder_path)
9
- source_folder_path = get_source_path(folder_path)
10
- template_paths_for(source_folder_path).each do |template_path|
8
+ def mount(absolute_folder_path)
9
+ template_paths_for(absolute_folder_path).each do |template_path|
11
10
 
12
- request_path = request_path_by(source_folder_path, template_path)
11
+ request_path = request_path_by(absolute_folder_path, template_path)
13
12
  template = Rack::App::FrontEnd::Template.new(template_path, fallback_handler: Rack::App::File::Streamer)
14
13
  create_endpoint_for(request_path, template)
15
14
 
@@ -39,7 +38,7 @@ class Rack::App::FrontEnd::FolderMounter
39
38
  if result.respond_to?(:each)
40
39
  response.body = result
41
40
  else
42
- response.write(result)
41
+ response.write(self.class.layout.render(result))
43
42
  end
44
43
  response.finish
45
44
  end
@@ -0,0 +1,21 @@
1
+ class Rack::App::FrontEnd::Layout < Rack::App::FrontEnd::Template
2
+
3
+ def render(content)
4
+ return render_result(content)
5
+ end
6
+
7
+ protected
8
+
9
+ def render_result(content)
10
+ if it_is_a_template? and layout_file_is_exists?
11
+ render_with_tilt_templates([], -> { content })
12
+ else
13
+ return content
14
+ end
15
+ end
16
+
17
+ def layout_file_is_exists?
18
+ File.exists?(@file_path)
19
+ end
20
+
21
+ end
@@ -0,0 +1,15 @@
1
+ require 'pwd'
2
+ module Rack::App::FrontEnd::Utils
3
+
4
+ extend self
5
+
6
+ def get_full_path(file_path,caller_index=1)
7
+ return nil if file_path.nil?
8
+ if file_path.to_s[0] == File::Separator
9
+ PWD.join(file_path)
10
+ else
11
+ File.join(File.dirname(caller[caller_index].split(':')[0]),file_path)
12
+ end
13
+ end
14
+
15
+ end
@@ -2,14 +2,25 @@ require 'rack/app'
2
2
  module Rack::App::FrontEnd
3
3
 
4
4
  require 'rack/app/front_end/version'
5
+ require 'rack/app/front_end/utils'
5
6
  require 'rack/app/front_end/template'
7
+ require 'rack/app/front_end/layout'
6
8
  require 'rack/app/front_end/view'
7
9
  require 'rack/app/front_end/folder_mounter'
8
10
 
9
- def mount_folder(path_from_project_root)
10
- Rack::App::FrontEnd::FolderMounter.new(self).mount(path_from_project_root)
11
+ def mount_folder(folder_path)
12
+ Rack::App::FrontEnd::FolderMounter.new(self).mount(Rack::App::FrontEnd::Utils.get_full_path(folder_path))
11
13
  end
12
14
 
13
15
  alias mount_templates_from mount_folder
14
16
 
17
+ def layout(layout_path=nil)
18
+ @layout = Rack::App::FrontEnd::Layout.new(Rack::App::FrontEnd::Utils.get_full_path(layout_path)) unless layout_path.nil?
19
+ @layout || Rack::App::FrontEnd::Layout.new(nil)
20
+ end
21
+
22
+ def default_layout
23
+ # code here
24
+ end
25
+
15
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-app-front_end
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Luzsi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-12-09 00:00:00.000000000 Z
11
+ date: 2015-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -127,8 +127,10 @@ files:
127
127
  - bin/setup
128
128
  - lib/rack/app/front_end.rb
129
129
  - lib/rack/app/front_end/folder_mounter.rb
130
+ - lib/rack/app/front_end/layout.rb
130
131
  - lib/rack/app/front_end/template.rb
131
132
  - lib/rack/app/front_end/template/plain_text.rb
133
+ - lib/rack/app/front_end/utils.rb
132
134
  - lib/rack/app/front_end/version.rb
133
135
  - lib/rack/app/front_end/view.rb
134
136
  - rack-app-front_end.gemspec