flame 4.18.1 → 5.0.0.rc6

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 (54) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +921 -0
  3. data/LICENSE.txt +19 -0
  4. data/README.md +135 -0
  5. data/lib/flame.rb +12 -4
  6. data/lib/flame/application.rb +93 -40
  7. data/lib/flame/config.rb +73 -0
  8. data/lib/flame/controller.rb +62 -98
  9. data/lib/flame/controller/actions.rb +122 -0
  10. data/lib/flame/controller/cookies.rb +44 -0
  11. data/lib/flame/controller/path_to.rb +63 -0
  12. data/lib/flame/dispatcher.rb +44 -73
  13. data/lib/flame/dispatcher/request.rb +33 -4
  14. data/lib/flame/dispatcher/routes.rb +66 -0
  15. data/lib/flame/dispatcher/static.rb +26 -15
  16. data/lib/flame/errors/argument_not_assigned_error.rb +7 -6
  17. data/lib/flame/errors/config_file_not_found_error.rb +17 -0
  18. data/lib/flame/errors/controller_not_found_error.rb +19 -0
  19. data/lib/flame/errors/route_arguments_order_error.rb +9 -8
  20. data/lib/flame/errors/route_extra_arguments_error.rb +18 -18
  21. data/lib/flame/errors/route_not_found_error.rb +8 -7
  22. data/lib/flame/errors/template_not_found_error.rb +6 -6
  23. data/lib/flame/path.rb +141 -55
  24. data/lib/flame/render.rb +46 -15
  25. data/lib/flame/router.rb +41 -127
  26. data/lib/flame/router/controller_finder.rb +56 -0
  27. data/lib/flame/router/route.rb +16 -54
  28. data/lib/flame/router/routes.rb +136 -0
  29. data/lib/flame/router/routes_refine.rb +144 -0
  30. data/lib/flame/router/routes_refine/mounting.rb +57 -0
  31. data/lib/flame/validators.rb +21 -11
  32. data/lib/flame/version.rb +1 -1
  33. metadata +139 -84
  34. data/bin/flame +0 -71
  35. data/lib/flame/application/config.rb +0 -43
  36. data/lib/flame/dispatcher/cookies.rb +0 -31
  37. data/template/.gitignore +0 -11
  38. data/template/Gemfile +0 -15
  39. data/template/Rakefile.erb +0 -64
  40. data/template/app.rb.erb +0 -7
  41. data/template/config.ru.erb +0 -20
  42. data/template/config/config.rb.erb +0 -14
  43. data/template/config/database.example.yml +0 -5
  44. data/template/config/sequel.rb.erb +0 -15
  45. data/template/config/thin.example.yml +0 -18
  46. data/template/controllers/_base_controller.rb.erb +0 -13
  47. data/template/db/.keep +0 -0
  48. data/template/helpers/.keep +0 -0
  49. data/template/lib/.keep +0 -0
  50. data/template/locales/en.yml +0 -0
  51. data/template/models/.keep +0 -0
  52. data/template/public/.keep +0 -0
  53. data/template/server +0 -49
  54. data/template/views/.keep +0 -0
data/bin/flame DELETED
@@ -1,71 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- require 'thor'
5
- require 'fileutils'
6
- require 'gorilla-patch/inflections'
7
- require 'erb'
8
-
9
- ## CLI Application
10
- class FlameCLI < Thor
11
- desc 'new APP', 'Generate new application directory with sub-directories'
12
- def new(app_name)
13
- FlameApp.new app_name
14
- end
15
-
16
- ## Class for Flame Application
17
- class FlameApp
18
- def initialize(app_name)
19
- @app_name = app_name
20
- New.build @app_name
21
- puts 'Done!'
22
- puts "\nMoving to '#{@app_name}' directory by:\n\ncd #{@app_name}\n\n"
23
- end
24
-
25
- ## Module for new application
26
- module New
27
- module_function
28
-
29
- using GorillaPatch::Inflections
30
-
31
- def build(app_name)
32
- @app_name = app_name
33
- @module_name = @app_name.camelize
34
- make_dir do
35
- copy_template
36
- end
37
- end
38
-
39
- def make_dir(&block)
40
- puts "Creating '#{@app_name}' directory..."
41
- FileUtils.mkdir @app_name
42
- FileUtils.cd @app_name, &block
43
- end
44
-
45
- def copy_template
46
- puts 'Copy template directories and files...'
47
- FileUtils.cp_r File.join(__dir__, '..', 'template', '.'), '.'
48
- clean_dirs
49
- render_templates
50
- end
51
-
52
- def clean_dirs
53
- puts 'Clean directories...'
54
- FileUtils.rm Dir[File.join('**', '*', '.keep')]
55
- end
56
-
57
- def render_templates
58
- puts 'Replace module names in template...'
59
- Dir[File.join('**', '*.erb')].each do |file|
60
- basename = File.basename(file, '.*')
61
- puts "- #{basename}"
62
- content = ERB.new(File.read(file)).result(binding)
63
- File.write(File.join(File.dirname(file), basename), content)
64
- FileUtils.rm file
65
- end
66
- end
67
- end
68
- end
69
- end
70
-
71
- FlameCLI.start(ARGV)
@@ -1,43 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Flame
4
- class Application
5
- ## Class for Flame::Application.config
6
- class Config < Hash
7
- def initialize(app, hash = {})
8
- @app = app
9
- replace(hash)
10
- end
11
-
12
- def [](key)
13
- result = super(key)
14
- if result.class <= Proc && result.parameters.empty?
15
- result = @app.class_exec(&result)
16
- end
17
- result
18
- end
19
-
20
- ## Method for loading YAML-files from config directory
21
- ## @param file [String, Symbol] file name (typecast to String with '.yml')
22
- ## @param key [Symbol, String, nil]
23
- ## key for allocating YAML in config Hash (typecast to Symbol)
24
- ## @param set [Boolean] allocating YAML in Config Hash
25
- ## @example Load SMTP file from `config/smtp.yml' to config[]
26
- ## config.load_yaml('smtp.yml')
27
- ## @example Load SMTP file without extension, by Symbol
28
- ## config.load_yaml(:smtp)
29
- ## @example Load SMTP file with other key to config[:mail]
30
- ## config.load_yaml('smtp.yml', key: :mail)
31
- ## @example Load SMTP file without allocating in config[]
32
- ## config.load_yaml('smtp.yml', set: false)
33
- def load_yaml(file, key: nil, set: true)
34
- file = "#{file}.yml" if file.is_a? Symbol
35
- file_path = File.join(self[:config_dir], file)
36
- yaml = YAML.load_file(file_path)
37
- key ||= File.basename(file, '.*')
38
- self[key.to_sym] = yaml if set
39
- yaml
40
- end
41
- end
42
- end
43
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Flame
4
- class Dispatcher
5
- ## Helper class for cookies
6
- class Cookies
7
- def initialize(request_cookies, response)
8
- @request_cookies = request_cookies
9
- @response = response
10
- end
11
-
12
- ## Get request cookies
13
- ## @param key [String, Symbol] name of cookie
14
- def [](key)
15
- @request_cookies[key.to_s]
16
- end
17
-
18
- ## Set (or delete) cookies for response
19
- ## @param key [String, Symbol] name of cookie
20
- ## @param new_value [Object, nil] value of cookie
21
- ## @example Set new value to `cat` cookie
22
- ## cookies['cat'] = 'nice cat'
23
- ## @example Delete `cat` cookie
24
- ## cookies['cat'] = nil
25
- def []=(key, new_value)
26
- return @response.delete_cookie(key.to_s, path: '/') if new_value.nil?
27
- @response.set_cookie(key.to_s, value: new_value, path: '/')
28
- end
29
- end
30
- end
31
- end
data/template/.gitignore DELETED
@@ -1,11 +0,0 @@
1
- # configuration
2
- config/*.yml
3
- !config/*example.yml
4
-
5
- # temp
6
- log/
7
- tmp/
8
- *.bak
9
-
10
- # dumps
11
- *.sql
data/template/Gemfile DELETED
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source 'https://rubygems.org'
4
-
5
- ## Framework
6
- gem 'flame'
7
- # gem 'flame-flash'
8
- # gem 'flame-r18n'
9
-
10
- ## Server
11
- gem 'thin'
12
-
13
- ## DataBase
14
- gem 'sequel'
15
- # gem 'pg'
@@ -1,64 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- namespace :db do
4
- ## Require libs and config
5
- require 'sequel'
6
- require File.join(__dir__, 'config', 'sequel.rb')
7
- ## Default path to db-files
8
- db_dir = File.join(__dir__, 'db')
9
-
10
- desc 'Run migrations'
11
- task :migrate, [:version] do |_t, args|
12
- Sequel.extension :migration
13
- migrations_dir = File.join(db_dir, 'migrations')
14
-
15
- if args[:version]
16
- puts "Migrating to version #{args[:version]}"
17
- Sequel::Migrator.run(
18
- <%= @module_name %>::DB,
19
- migrations_dir,
20
- target: args[:version].to_i
21
- )
22
- else
23
- puts 'Migrating to latest'
24
- Sequel::Migrator.run(<%= @module_name %>::DB, migrations_dir)
25
- end
26
-
27
- Rake::Task['db:schema:dump'].invoke('same_db=true')
28
- end
29
-
30
- desc 'Run seeds'
31
- task :seed do |_t|
32
- require 'sequel/extensions/seed'
33
- seeds_dir = File.join(db_dir, 'seeds')
34
-
35
- ## Doesn't support version yet
36
- puts 'Seeding latest'
37
- Sequel::Seeder.apply(<%= @module_name %>::DB, seeds_dir)
38
- end
39
-
40
- namespace :schema do
41
- schema_filename = '001_schema.rb'
42
-
43
- desc 'Run schema dump'
44
- task :dump do |_t|
45
- <%= @module_name %>::DB.extension :schema_dumper
46
- puts 'Dump latest schema'
47
- dump = <%= @module_name %>::DB.dump_schema_migration(
48
- same_db: env_true?('same_db')
49
- )
50
- File.write(File.join(db_dir, schema_filename), dump)
51
- end
52
-
53
- desc 'Run schema load'
54
- task :load do |_t|
55
- Sequel.extension :migration
56
- puts 'Load latest schema'
57
- Sequel::Migrator.run(<%= @module_name %>::DB, db_dir, target: 1)
58
- end
59
- end
60
- end
61
-
62
- def env_true?(key)
63
- %(true yes 1 y).include?(ENV[key].to_s.downcase)
64
- end
data/template/app.rb.erb DELETED
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module <%= @module_name %>
4
- ## Class for application (mounting controllers)
5
- class Application
6
- end
7
- end
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- ## Require gems
4
- require 'bundler'
5
- Bundler.require
6
-
7
- ## Require project
8
- Dir[File.join(
9
- __dir__, '{config,models,helpers,controllers}', '{,**}', '{_,}*.rb'
10
- )].each { |file| require file }
11
-
12
- ## Require application
13
- require_relative './app'
14
-
15
- ## Use middlewares
16
- use Rack::Session::Cookie, key: 'rack.session', secret: 'dummy_secret'
17
- use Rack::CommonLogger
18
-
19
- ## Run application
20
- run <%= @module_name %>::Application
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module <%= @module_name %>
4
- ## Constants
5
- SITE_NAME = '<%= @module_name %>'.freeze
6
-
7
- ## Configuration for application
8
- module Config
9
- def self.included(app)
10
- ## Translations
11
- # Flame::R18n.config(app)
12
- end
13
- end
14
- end
@@ -1,5 +0,0 @@
1
- :adapter: 'postgres'
2
- :host: 'localhost'
3
- :database: 'database'
4
- :user: 'user'
5
- :password: 'password'
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'yaml'
4
-
5
- ## Database initialize for Sequel
6
- module <%= @module_name %>
7
- # Sequel::Model.plugin :timestamps
8
- # Sequel::Model.raise_on_save_failure = false
9
-
10
- DB = Sequel.connect(
11
- YAML.load_file(File.join(__dir__, 'database.yml'))
12
- )
13
-
14
- # DB.extension :pg_enum
15
- end
@@ -1,18 +0,0 @@
1
- ---
2
- # user: www-data
3
- # group: www-data
4
- pid: tmp/pids/thin.pid
5
- timeout: 30
6
- wait: 30
7
- log: log/thin.log
8
- max_conns: 1024
9
- require: []
10
- environment: development # production
11
- max_persistent_conns: 512
12
- servers: 1
13
- threaded: true
14
- no-epoll: true
15
- daemonize: true
16
- socket: tmp/sockets/thin.sock
17
- chdir: /path/to/the/project
18
- # tag: a-name-to-show-up-in-ps aux
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module <%= @module_name %>
4
- ## Base controller for any others controllers
5
- class Controller < Flame::Controller
6
- # include Flame::R18n
7
-
8
- def execute(method)
9
- # session[:locale] = params[:locale] || 'ru'
10
- super
11
- end
12
- end
13
- end
data/template/db/.keep DELETED
File without changes
File without changes
data/template/lib/.keep DELETED
File without changes
File without changes
File without changes
File without changes
data/template/server DELETED
@@ -1,49 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- ## Functons
5
- def show_usage
6
- puts 'Usage: ./server COMMAND'
7
- puts 'COMMAND is one of:'
8
- puts ' start - Start server'
9
- puts ' stop - Stop server'
10
- puts ' restart - Stop/Start server'
11
- puts ' monitor - Show log'
12
- puts ' devel - Restart/Monitor server'
13
- end
14
-
15
- def start_server
16
- system 'rm log/*'
17
- system 'thin -C config/thin.yml start'
18
- end
19
-
20
- def stop_server
21
- system 'thin -C config/thin.yml stop'
22
- end
23
-
24
- def restart_server
25
- stop_server
26
- start_server
27
- end
28
-
29
- def monitor_server
30
- system 'tail -f log/thin.*.log'
31
- end
32
-
33
- ## Runtime
34
- case ARGV[0]
35
- when 'start'
36
- start_server
37
- when 'stop'
38
- stop_server
39
- when 'restart'
40
- restart_server
41
- when 'monitor'
42
- monitor_server
43
- when 'devel'
44
- restart_server
45
- monitor_server
46
- else
47
- puts "Unknown command #{ARGV[0]}"
48
- show_usage
49
- end
data/template/views/.keep DELETED
File without changes