ella 0.1.2

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.
Files changed (47) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +7 -0
  3. data/.rspec +3 -0
  4. data/CHANGELOG.md +5 -0
  5. data/CODE_OF_CONDUCT.md +74 -0
  6. data/Gemfile +12 -0
  7. data/Gemfile.lock +56 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +115 -0
  10. data/ella-0.1.0.gem +0 -0
  11. data/ella.gemspec +26 -0
  12. data/exe/ella +14 -0
  13. data/lib/ella.rb +45 -0
  14. data/lib/ella/cli.rb +114 -0
  15. data/lib/ella/controller.rb +36 -0
  16. data/lib/ella/generator.rb +42 -0
  17. data/lib/ella/generator/config_generator.rb +16 -0
  18. data/lib/ella/generator/controller_generator.rb +34 -0
  19. data/lib/ella/generator/destroyer.rb +44 -0
  20. data/lib/ella/generator/gemfile_generator.rb +15 -0
  21. data/lib/ella/generator/model_generator.rb +27 -0
  22. data/lib/ella/generator/project_generator.rb +88 -0
  23. data/lib/ella/generator/rackfile_generator.rb +76 -0
  24. data/lib/ella/generator/view_generator.rb +42 -0
  25. data/lib/ella/log.rb +70 -0
  26. data/lib/ella/model.rb +0 -0
  27. data/lib/ella/name_formatter.rb +32 -0
  28. data/lib/ella/pipeline.rb +99 -0
  29. data/lib/ella/reloader.rb +430 -0
  30. data/lib/ella/server.rb +107 -0
  31. data/lib/ella/template.rb +46 -0
  32. data/lib/ella/test.rb +9 -0
  33. data/lib/ella/version.rb +3 -0
  34. data/lib/ella/view.rb +0 -0
  35. data/templates/Gemfile +12 -0
  36. data/templates/configs/css.rb +20 -0
  37. data/templates/configs/js.rb +19 -0
  38. data/templates/configs/puma.rb +5 -0
  39. data/templates/controller +9 -0
  40. data/templates/controllers/root.rb +7 -0
  41. data/templates/main.rb +8 -0
  42. data/templates/model +6 -0
  43. data/templates/test +22 -0
  44. data/templates/views/layout.erb +18 -0
  45. data/templates/views/root/index.erb +3 -0
  46. data/version.txt +1 -0
  47. metadata +94 -0
@@ -0,0 +1,107 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'pipeline'
4
+
5
+ module Ella
6
+ # This is not so much a server as a something which starts of the server and
7
+ # various listeners and initializers associated with Ella. From the point of
8
+ # view of the rest of Ella, this will be the server, though.
9
+ # This also restarts the server in development mode, something Sinatra is a
10
+ # bit shifty about on its own, due to Ruby restrictions.
11
+ class Server
12
+ def initialize(mode: 'development', port: nil)
13
+ Ella.find_root
14
+ Log.yell("Starting server in #{mode} mode...")
15
+ @mode = mode
16
+ @port = port
17
+
18
+ establish_pipelines
19
+ end
20
+
21
+ def run
22
+ Ella.find_root
23
+ @mode_path = File.join(Dir.pwd, 'temp/mode')
24
+ File.open(@mode_path, 'w') { |f| f.puts(@mode) }
25
+ RackfileGenerator.new.run
26
+
27
+ Log.info('Staring Puma...')
28
+ @mode == 'production' ? start_production_server : start_development_listener_loop
29
+ end
30
+
31
+ def css_path
32
+ @pipelines[:css].path
33
+ end
34
+
35
+ def js_path
36
+ @pipelines[:js].path
37
+ end
38
+
39
+ private
40
+
41
+ def start_production_server
42
+ system("puma #{"-p #{@port}" if @port} -e #{@mode} -C \"configs/puma.rb\" rack.ru", out: $stdout, err: :out)
43
+ end
44
+
45
+ # As the name implies, it is necessary to keep the program idling while in
46
+ # development, in order have the listeners contiue to run.
47
+ def keep_listeners_alive
48
+ sleep
49
+ rescue Interrupt
50
+ sleep 1
51
+ File.delete(@mode_path) if File.exist?(@mode_path)
52
+ Log.exit_message('Ella is shutting down. Moimoi.')
53
+ end
54
+
55
+ # This restarts the actual puma server, but not Ella's listerners, which
56
+ # remain running. Sinatra's reloader only works for files that exist when
57
+ # the server started. To my knowledge this has to be the case.
58
+ # See Puma documentation on SIGUSR2 for more info.
59
+ def restart
60
+ mode = File.open(File.join(Dir.pwd, 'temp/mode')).read.chomp
61
+ if mode == 'development'
62
+ RackfileGenerator.new.run
63
+ pid = File.open(File.join(Dir.pwd, 'temp/puma.pid')).read.to_i
64
+ Process.kill('SIGUSR2', pid)
65
+ end
66
+ end
67
+
68
+ # Modified is handled by Sinatra reloader, if anything because the console
69
+ # output is less spammy.
70
+ def start_model_controller_listeners
71
+ input_dirs = [File.join(Dir.pwd, 'controllers'), File.join(Dir.pwd, 'models')]
72
+ @listener = Listen.to(*input_dirs) do |modified, added, removed|
73
+ restart if !added.empty? || !removed.empty?
74
+ rescue => e
75
+ # You never know with listen.
76
+ puts e
77
+ end
78
+ @listener.start
79
+ end
80
+
81
+ def start_development_listener_loop
82
+ start_development_server
83
+ start_model_controller_listeners
84
+ keep_listeners_alive
85
+ end
86
+
87
+ # Do not refactor unless you are 100% sure you are comfortable with Ruby forking.
88
+ def start_development_server
89
+ unless @pid = fork
90
+ exec("puma #{"-p #{@port}" if @port} -e #{@mode} -C \"configs/puma.rb\" rack.ru", out: $stdout, err: :out)
91
+ end
92
+ end
93
+
94
+ def establish_pipelines
95
+ @pipelines = { css: Pipeline.new('css'), js: Pipeline.new('js') }
96
+ # Listener runs pipeline in development, otherwise, the pipeline runs once
97
+ # before starting the server.
98
+ if @mode == 'development'
99
+ Log.info('Starting pipeline listeners...')
100
+ @pipelines.map { |_, v| v.listen }
101
+ else
102
+ Log.info('Precompiling assets...')
103
+ @pipelines.map { |_, v| v.run }
104
+ end
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'erb'
4
+
5
+ module Ella
6
+ # Class to handle naming, copying, and processing the various templates that
7
+ # the Ella generators use.
8
+ class Template
9
+ TEMPLATE_DIRECTORY = File.expand_path('../../templates', __dir__)
10
+
11
+ # If generic_template is nil, this class will look for a specific template based on the filename.
12
+ def initialize(filename, generic_template: nil, template_vars: nil)
13
+ @filename = filename
14
+ @destination = File.join(Dir.pwd, @filename)
15
+ @generic_template = generic_template
16
+ @template_vars = template_vars
17
+ end
18
+
19
+ def write
20
+ Log.create(@filename)
21
+ if file_exists?
22
+ Log.error('File already exists. Skipping.')
23
+ else
24
+ File.open(@destination, 'w') { |f| f.write(data) }
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ def file_exists?
31
+ File.exist?(@destination)
32
+ end
33
+
34
+ def render_erb(template)
35
+ @template_vars ? ERB.new(template, nil, '-').result_with_hash(@template_vars) : template
36
+ end
37
+
38
+ def template_path
39
+ File.join(TEMPLATE_DIRECTORY, @generic_template || @filename)
40
+ end
41
+
42
+ def data
43
+ @generic_template == :blank ? '' : render_erb(File.open(template_path, 'r').read)
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,9 @@
1
+ module Ella
2
+ # Runs tests for user project. Currently default to RSpec.
3
+ class Test
4
+ def self.run
5
+ Ella.find_root
6
+ exec('rspec -P "tests/*.rb, tests/*/*.rb"')
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module Ella
2
+ VERSION = '0.1.2'
3
+ end
File without changes
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ ruby '2.7.2'
6
+
7
+ gem 'puma', '~>5.0'
8
+ gem 'sinatra', '~>2.1'
9
+
10
+ gem 'colorize', '~>0.8'
11
+ gem 'listen', '~>3.3'
12
+ gem 'rspec', '~>3.1'
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This is the assets pipeline for CSS. See the documentation for more info. Kill time.
4
+ module Ella
5
+ class Pipeline
6
+ def css
7
+ # Welcome to your CSS filter! Everything here will be outputted into a
8
+ # single file, whose path is available by running the method "css_path",
9
+ # which can be called from a view.
10
+
11
+ # The method 'asset_data(*file_names)' will return the data for all files
12
+ # that are in the relevant assets directory. For CSS that is "assets/css/"
13
+
14
+ # A quick and dirty example of how you might call Sass here:
15
+ # require 'sassc'
16
+ # raw_data = asset_data('main.scss', 'other_file.scss')
17
+ # SassC::Engine.new(raw_data, style: :compressed).render
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This is the assets pipeline for Javascript. See the documentation for more info. Kill time.
4
+ module Ella
5
+ class Pipeline
6
+ def js
7
+ # Welcome to your Javascript filter! Everything here will be outputted into
8
+ # a single file, whose path is available by running the method "js_path",
9
+ # which can be called from a view.
10
+
11
+ # The method 'asset_data(*file_names)' will return the data for all files
12
+ # that are in the relevant assets directory. For JS that is "assets/js/"
13
+
14
+ # A quick and dirty example of how use might implement a simple minifier:
15
+ # raw_data = asset_data('main.js', 'other_file.js')
16
+ # raw_data.gsub("\n", '')
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Puma configuration file.
4
+ bind 'tcp://localhost:7654'
5
+ pidfile File.join(__dir__, '../temp/puma.pid')
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ class <%= name.pascal_case %>Controller < Ella::Controller
4
+ <% files.each_with_index do |f, i| -%>
5
+ get '/<%= name.snake_case %>/<%= f %>' do
6
+ erb :'<%= name.snake_case %>/<%= f %>'
7
+ end<%= "\n" if i != files.length - 1 %>
8
+ <% end -%>
9
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RootController < Ella::Controller
4
+ get '/' do
5
+ erb :'root/index'
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # You can put any code you like in this file and it will load when you run the
4
+ # server.
5
+ # The Ella server depends on this file existing in the root directory, so please
6
+ # do not remove or delete it.
7
+ class <%= name.pascal_case %> < Ella::Controller
8
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ class <%= name.pascal_case %>
4
+ # This class will be accessable from your controllers. If you are looking for
5
+ # an ORM, try the 'sequel' package.
6
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ella'
4
+ require_relative '../../controllers/<%= name.snake_case %>'
5
+
6
+ # Test file for <%= name.pascal_case %>.
7
+ # See RSpec documentation for more into.
8
+ RSpec.describe <%= name.pascal_case + 'Controller' if @controller %> do
9
+ before(:all) do
10
+ end
11
+
12
+ it 'knows what true is' do
13
+ expect(true).to be true
14
+ end
15
+
16
+ it 'knows what false is' do
17
+ expect(false).to be true
18
+ end
19
+
20
+ after (:all) do
21
+ end
22
+ end
@@ -0,0 +1,18 @@
1
+ <!doctype html>
2
+
3
+ <html lang="en">
4
+ <head>
5
+ <meta charset="utf-8">
6
+
7
+ <title><%= name.human %></title>
8
+ <meta name="description" content="FILL ME IN!">
9
+ <meta name="author" content="FILL ME IN!">
10
+
11
+ <link rel="stylesheet" href="<%%= css_path %>">
12
+ </head>
13
+
14
+ <body>
15
+ <%%= yield %>
16
+ <script src="<%%= js_path %>"></script>
17
+ </body>
18
+ </html>
@@ -0,0 +1,3 @@
1
+ <h1>Welcome to Ella!</h1>
2
+
3
+ <p>This is the root page of your new project. Feel free to change everything.</p>
@@ -0,0 +1 @@
1
+ 0.1.0
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ella
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Kyle Church
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-11-27 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Ella is a web framework which seeks which seeks to find a balance between
14
+ the simplicity of a microframework and the conveniences of a large, opinionated
15
+ framework. Ella uses Sinatra for its controllers and routing.
16
+ email:
17
+ - kyle@kylechur.ch
18
+ executables:
19
+ - ella
20
+ extensions: []
21
+ extra_rdoc_files: []
22
+ files:
23
+ - ".gitignore"
24
+ - ".rspec"
25
+ - CHANGELOG.md
26
+ - CODE_OF_CONDUCT.md
27
+ - Gemfile
28
+ - Gemfile.lock
29
+ - LICENSE.txt
30
+ - README.md
31
+ - ella-0.1.0.gem
32
+ - ella.gemspec
33
+ - exe/ella
34
+ - lib/ella.rb
35
+ - lib/ella/cli.rb
36
+ - lib/ella/controller.rb
37
+ - lib/ella/generator.rb
38
+ - lib/ella/generator/config_generator.rb
39
+ - lib/ella/generator/controller_generator.rb
40
+ - lib/ella/generator/destroyer.rb
41
+ - lib/ella/generator/gemfile_generator.rb
42
+ - lib/ella/generator/model_generator.rb
43
+ - lib/ella/generator/project_generator.rb
44
+ - lib/ella/generator/rackfile_generator.rb
45
+ - lib/ella/generator/view_generator.rb
46
+ - lib/ella/log.rb
47
+ - lib/ella/model.rb
48
+ - lib/ella/name_formatter.rb
49
+ - lib/ella/pipeline.rb
50
+ - lib/ella/reloader.rb
51
+ - lib/ella/server.rb
52
+ - lib/ella/template.rb
53
+ - lib/ella/test.rb
54
+ - lib/ella/version.rb
55
+ - lib/ella/view.rb
56
+ - templates/Gemfile
57
+ - templates/configs/css.rb
58
+ - templates/configs/js.rb
59
+ - templates/configs/puma.rb
60
+ - templates/controller
61
+ - templates/controllers/root.rb
62
+ - templates/main.rb
63
+ - templates/model
64
+ - templates/test
65
+ - templates/views/layout.erb
66
+ - templates/views/root/index.erb
67
+ - version.txt
68
+ homepage: https://bitbucket.org/SurdEgg/ella/src/master/
69
+ licenses:
70
+ - MIT
71
+ metadata:
72
+ homepage_uri: https://bitbucket.org/SurdEgg/ella/src/master/
73
+ source_code_uri: https://bitbucket.org/SurdEgg/ella/src/master/
74
+ changelog_uri: https://bitbucket.org/SurdEgg/ella/src/master/CHANGELOG.md
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: 2.7.0
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubygems_version: 3.1.4
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: A convenience-focused mesoframework for web development.
94
+ test_files: []