rack-app-front_end 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +2 -0
- data/README.md +36 -0
- data/Rakefile +6 -0
- data/VERSION +1 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/rack/app/front_end.rb +15 -0
- data/lib/rack/app/front_end/folder_mounter.rb +57 -0
- data/lib/rack/app/front_end/template.rb +37 -0
- data/lib/rack/app/front_end/template/plain_text.rb +27 -0
- data/lib/rack/app/front_end/version.rb +4 -0
- data/lib/rack/app/front_end/view.rb +13 -0
- data/rack-app-front_end.gemspec +32 -0
- metadata +158 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 66e2c7fe3be8727a7f5046ae0d7a5d0b9942d85b
|
4
|
+
data.tar.gz: 1924cc9d774971c0cb4b5911313ccceac7d85866
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d4530e60a4cbed9c90fa39692d0253ee81c494a540a741436814b5fceef9bc3d649ba711fdc247f5a3267b9f7e6da4d4da8098478851276073fc207598d738c2
|
7
|
+
data.tar.gz: 6df2bd31cbbccaae9019a101b5896262bcd3be1eb969302f29d0dfdafc707d7c6f8d13b251f0d6b6404bb17e043d8184c6d7b0a81662c2568acd730852010710
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Rack::App::Mvc
|
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
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'rack-app-mvc'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install rack-app-mvc
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rack-app-mvc. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
36
|
+
|
data/Rakefile
ADDED
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "rack/app/front_end"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rack/app'
|
2
|
+
module Rack::App::FrontEnd
|
3
|
+
|
4
|
+
require 'rack/app/front_end/version'
|
5
|
+
require 'rack/app/front_end/template'
|
6
|
+
require 'rack/app/front_end/view'
|
7
|
+
require 'rack/app/front_end/folder_mounter'
|
8
|
+
|
9
|
+
def mount_folder(path_from_project_root)
|
10
|
+
Rack::App::FrontEnd::FolderMounter.new(self).mount(path_from_project_root)
|
11
|
+
end
|
12
|
+
|
13
|
+
alias mount_templates_from mount_folder
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'pwd'
|
2
|
+
class Rack::App::FrontEnd::FolderMounter
|
3
|
+
|
4
|
+
def initialize(app_class)
|
5
|
+
@app_class = app_class
|
6
|
+
end
|
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|
|
11
|
+
|
12
|
+
request_path = request_path_by(source_folder_path, template_path)
|
13
|
+
template = Rack::App::FrontEnd::Template.new(template_path, fallback_handler: Rack::App::File::Streamer)
|
14
|
+
create_endpoint_for(request_path, template)
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def get_source_path(folder_path)
|
20
|
+
if folder_path.to_s[0] == File::Separator
|
21
|
+
PWD.join(folder_path)
|
22
|
+
else
|
23
|
+
File.join(File.dirname(caller[1].split(':')[0]),folder_path)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
protected
|
28
|
+
|
29
|
+
def template_paths_for(source_folder_path)
|
30
|
+
Dir.glob(File.join(source_folder_path, '**', '*'))
|
31
|
+
.select { |p| not File.directory?(p) }
|
32
|
+
end
|
33
|
+
|
34
|
+
def create_endpoint_for(request_path, template)
|
35
|
+
@app_class.class_eval do
|
36
|
+
|
37
|
+
get(request_path) do
|
38
|
+
result = template.render(self)
|
39
|
+
if result.respond_to?(:each)
|
40
|
+
response.body = result
|
41
|
+
else
|
42
|
+
response.write(result)
|
43
|
+
end
|
44
|
+
response.finish
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def request_path_by(source_folder_path, template_path)
|
51
|
+
Rack::Utils.clean_path_info template_path
|
52
|
+
.sub(source_folder_path, '')
|
53
|
+
.split(File::Separator).join('/')
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'tilt'
|
2
|
+
class Rack::App::FrontEnd::Template
|
3
|
+
|
4
|
+
require 'rack/app/front_end/template/plain_text'
|
5
|
+
|
6
|
+
def render(*args, &block)
|
7
|
+
return render_result(*args, &block)
|
8
|
+
end
|
9
|
+
|
10
|
+
protected
|
11
|
+
|
12
|
+
def initialize(file_path,fallback_handler: Rack::App::FrontEnd::Template::PlainText)
|
13
|
+
@fallback_handler = fallback_handler
|
14
|
+
@file_path = file_path
|
15
|
+
end
|
16
|
+
|
17
|
+
def render_result(*args, &block)
|
18
|
+
if it_is_a_template?
|
19
|
+
render_with_tilt_templates(args, block)
|
20
|
+
else
|
21
|
+
@fallback_handler.new(@file_path).render(*args, &block)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def it_is_a_template?
|
26
|
+
not Tilt.templates_for(@file_path).empty?
|
27
|
+
end
|
28
|
+
|
29
|
+
def render_with_tilt_templates(args, block)
|
30
|
+
file_content = File.read(@file_path)
|
31
|
+
Tilt.templates_for(@file_path).each do |template_engine|
|
32
|
+
file_content = template_engine.new { file_content }.render(*args, &block)
|
33
|
+
end
|
34
|
+
return file_content
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class Rack::App::FrontEnd::Template::PlainText
|
2
|
+
|
3
|
+
include Enumerable
|
4
|
+
|
5
|
+
def each(&block)
|
6
|
+
file { |f| f.each(&block) }
|
7
|
+
end
|
8
|
+
|
9
|
+
def render(object=nil)
|
10
|
+
file { |f| f.read }
|
11
|
+
end
|
12
|
+
|
13
|
+
protected
|
14
|
+
|
15
|
+
def initialize(file_path)
|
16
|
+
@file_path = file_path
|
17
|
+
@file = File.open(file_path)
|
18
|
+
end
|
19
|
+
|
20
|
+
def file(&block)
|
21
|
+
@file.reopen(@file_path) if @file.closed?
|
22
|
+
return block.call(@file)
|
23
|
+
ensure
|
24
|
+
@file.close
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class Rack::App::FrontEnd::View
|
2
|
+
|
3
|
+
def render(view_file_basename)
|
4
|
+
file_path = File.join(class_current_folder, view_file_basename)
|
5
|
+
|
6
|
+
Rack::App::FrontEnd::Template.new(file_path).render(self)
|
7
|
+
end
|
8
|
+
|
9
|
+
def class_current_folder
|
10
|
+
method(:call).source_location.first.sub(/.rb$/,'')
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rack/app/front_end/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
|
8
|
+
spec.name = "rack-app-front_end"
|
9
|
+
spec.version = Rack::App::FrontEnd::VERSION
|
10
|
+
spec.authors = ["Adam Luzsi"]
|
11
|
+
spec.email = ["adamluzsi@gmail.com"]
|
12
|
+
|
13
|
+
spec.summary = %q{Rack::App FrontEnd framework to create beautiful website with style}
|
14
|
+
spec.description = %q{Rack::App FrontEnd framework to create beautiful website with style}
|
15
|
+
spec.homepage = 'http://www.rack-app.com/'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "rspec"
|
25
|
+
|
26
|
+
spec.add_development_dependency "maruku"
|
27
|
+
|
28
|
+
spec.add_dependency 'rack-app'
|
29
|
+
spec.add_dependency 'tilt'
|
30
|
+
spec.add_dependency 'pwd'
|
31
|
+
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-app-front_end
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adam Luzsi
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-12-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: maruku
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rack-app
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: tilt
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pwd
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: Rack::App FrontEnd framework to create beautiful website with style
|
112
|
+
email:
|
113
|
+
- adamluzsi@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- ".rspec"
|
120
|
+
- ".travis.yml"
|
121
|
+
- CODE_OF_CONDUCT.md
|
122
|
+
- Gemfile
|
123
|
+
- README.md
|
124
|
+
- Rakefile
|
125
|
+
- VERSION
|
126
|
+
- bin/console
|
127
|
+
- bin/setup
|
128
|
+
- lib/rack/app/front_end.rb
|
129
|
+
- lib/rack/app/front_end/folder_mounter.rb
|
130
|
+
- lib/rack/app/front_end/template.rb
|
131
|
+
- lib/rack/app/front_end/template/plain_text.rb
|
132
|
+
- lib/rack/app/front_end/version.rb
|
133
|
+
- lib/rack/app/front_end/view.rb
|
134
|
+
- rack-app-front_end.gemspec
|
135
|
+
homepage: http://www.rack-app.com/
|
136
|
+
licenses: []
|
137
|
+
metadata: {}
|
138
|
+
post_install_message:
|
139
|
+
rdoc_options: []
|
140
|
+
require_paths:
|
141
|
+
- lib
|
142
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
requirements: []
|
153
|
+
rubyforge_project:
|
154
|
+
rubygems_version: 2.4.8
|
155
|
+
signing_key:
|
156
|
+
specification_version: 4
|
157
|
+
summary: Rack::App FrontEnd framework to create beautiful website with style
|
158
|
+
test_files: []
|