Module: Volt
- Includes:
- Configurations
- Defined in:
- lib/volt/server/rack/opal_files.rb,
lib/volt.rb,
lib/volt/cli.rb,
lib/volt/boot.rb,
lib/volt/config.rb,
lib/volt/server.rb,
lib/volt/page/page.rb,
lib/volt/cli/runner.rb,
lib/volt/models/url.rb,
lib/volt/page/tasks.rb,
lib/volt/spec/setup.rb,
lib/volt/cli/console.rb,
lib/volt/utils/ejson.rb,
lib/volt/models/model.rb,
lib/volt/page/channel.rb,
lib/volt/models/cursor.rb,
lib/volt/page/document.rb,
lib/volt/router/routes.rb,
lib/volt/page/sub_context.rb,
lib/volt/page/url_tracker.rb,
lib/volt/tasks/dispatcher.rb,
lib/volt/volt/environment.rb,
lib/volt/cli/asset_compile.rb,
lib/volt/page/channel_stub.rb,
lib/volt/models/array_model.rb,
lib/volt/models/model_state.rb,
lib/volt/models/validations.rb,
lib/volt/reactive/eventable.rb,
lib/volt/tasks/task_handler.rb,
lib/volt/utils/generic_pool.rb,
lib/volt/reactive/dependency.rb,
lib/volt/utils/local_storage.rb,
lib/volt/utils/local_storage.rb,
lib/volt/models/model_helpers.rb,
lib/volt/models/model_wrapper.rb,
lib/volt/page/document_events.rb,
lib/volt/reactive/computation.rb,
lib/volt/data_stores/data_store.rb,
lib/volt/models/persistors/base.rb,
lib/volt/page/template_renderer.rb,
lib/volt/reactive/reactive_hash.rb,
lib/volt/models/persistors/flash.rb,
lib/volt/models/persistors/store.rb,
lib/volt/page/targets/dom_target.rb,
lib/volt/reactive/reactive_array.rb,
lib/volt/server/rack/asset_files.rb,
lib/volt/server/rack/index_files.rb,
lib/volt/data_stores/mongo_driver.rb,
lib/volt/models/persistors/params.rb,
lib/volt/page/bindings/if_binding.rb,
lib/volt/page/targets/dom_section.rb,
lib/volt/reactive/hash_dependency.rb,
lib/volt/server/component_handler.rb,
lib/volt/models/persistors/cookies.rb,
lib/volt/page/targets/base_section.rb,
lib/volt/page/targets/dom_template.rb,
lib/volt/page/bindings/base_binding.rb,
lib/volt/page/bindings/each_binding.rb,
lib/volt/server/component_templates.rb,
lib/volt/server/rack/component_code.rb,
lib/volt/models/model_hash_behaviour.rb,
lib/volt/page/bindings/event_binding.rb,
lib/volt/reactive/reactive_accessors.rb,
lib/volt/server/rack/component_paths.rb,
lib/volt/utils/generic_counting_pool.rb,
lib/volt/controllers/model_controller.rb,
lib/volt/extra_core/inflector/methods.rb,
lib/volt/models/persistors/array_store.rb,
lib/volt/models/persistors/local_store.rb,
lib/volt/models/persistors/model_store.rb,
lib/volt/models/persistors/store_state.rb,
lib/volt/page/bindings/content_binding.rb,
lib/volt/page/string_template_renderer.rb,
lib/volt/page/targets/attribute_target.rb,
lib/volt/server/html_parser/each_scope.rb,
lib/volt/server/html_parser/view_scope.rb,
lib/volt/server/rack/source_map_server.rb,
app/volt/controllers/notices_controller.rb,
lib/volt/page/bindings/template_binding.rb,
lib/volt/page/targets/attribute_section.rb,
lib/volt/server/html_parser/view_parser.rb,
lib/volt/models/persistors/store_factory.rb,
lib/volt/page/bindings/attribute_binding.rb,
lib/volt/page/bindings/component_binding.rb,
lib/volt/server/html_parser/view_handler.rb,
lib/volt/extra_core/inflector/inflections.rb,
lib/volt/server/html_parser/if_view_scope.rb,
lib/volt/server/socket_connection_handler.rb,
lib/volt/server/html_parser/textarea_scope.rb,
lib/volt/models/validators/length_validator.rb,
lib/volt/models/validators/unique_validator.rb,
lib/volt/server/html_parser/attribute_scope.rb,
lib/volt/server/rack/component_html_renderer.rb,
lib/volt/models/persistors/model_identity_map.rb,
lib/volt/models/validators/presence_validator.rb,
lib/volt/server/html_parser/sandlebars_parser.rb,
lib/volt/server/socket_connection_handler_stub.rb,
lib/volt/models/persistors/query/query_listener.rb,
lib/volt/page/targets/helpers/comment_searchers.rb,
lib/volt/page/targets/binding_document/base_node.rb,
lib/volt/page/targets/binding_document/html_node.rb,
lib/volt/models/persistors/query/query_listener_pool.rb,
lib/volt/page/targets/binding_document/component_node.rb,
lib/volt/page/bindings/template_binding/grouped_controllers.rb
Overview
Some template bindings share the controller with other template bindings based on a name. This class keeps track of the number of templates using this controller and clears it once no one else is using it. Use #get or #inc to add to the count. #clear removes 1 from the count. When the count is 0, delete the controller.
Defined Under Namespace
Modules: AttributeScope, CommentSearchers, Eventable, Inflector, LocalStorage, ModelHashBehaviour, ModelHelpers, ModelState, ModelWrapper, Persistors, ReactiveAccessors, Validations Classes: ArrayModel, AssetFiles, AttributeBinding, AttributeSection, AttributeTarget, BaseBinding, BaseNode, BaseSection, CLI, Channel, ChannelStub, ComponentBinding, ComponentCode, ComponentHandler, ComponentHtmlRenderer, ComponentNode, ComponentPaths, ComponentTemplates, Computation, Console, ContentBinding, Cursor, DataStore, Dependency, Dispatcher, Document, DocumentEvents, DomSection, DomTarget, DomTemplate, EJson, EachBinding, EachScope, Environment, EventBinding, GenericCountingPool, GenericPool, GroupedControllers, HTMLParseError, HashDependency, HtmlNode, IfBinding, IfViewScope, IndexFiles, JSEvent, LengthValidator, Listener, Model, ModelController, ModelIdentityMap, NilMethodCall, NoticesController, OpalFiles, Page, PresenceValidator, QueryListener, QueryListenerPool, ReactiveArray, ReactiveHash, Routes, SandlebarsParser, Server, SocketConnectionHandler, SocketConnectionHandlerStub, SourceMapServer, StringTemplateRender, SubContext, TaskHandler, Tasks, TemplateBinding, TemplateRenderer, TextareaScope, URL, UniqueValidator, UrlTracker, ViewHandler, ViewParser, ViewScope
Class Attribute Summary collapse
Class Method Summary collapse
- .boot(app_path) ⇒ Object
- .client? ⇒ Boolean
- .defaults ⇒ Object
- .env ⇒ Object
- .in_browser? ⇒ Boolean
-
.reset_config! ⇒ Object
Resets the configuration to the default (empty hash).
-
.run_files_in_config_folder ⇒ Object
Load in all .rb files in the config folder.
- .server? ⇒ Boolean
- .source_maps? ⇒ Boolean
- .spec_setup(app_path = '.') ⇒ Object
-
.user ⇒ Object
Return the current user.
-
.user_id ⇒ Object
Get the user_id from the cookie.
Class Attribute Details
.logger ⇒ Object
41 42 43 |
# File 'lib/volt.rb', line 41 def logger @logger ||= Logger.new(STDOUT) end |
.root ⇒ Object
19 20 21 |
# File 'lib/volt.rb', line 19 def root @root ||= File.(Dir.pwd) end |
Class Method Details
.boot(app_path) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/volt/boot.rb', line 10 def self.boot(app_path) # Run the app config to load all users config files Volt.run_files_in_config_folder if Volt.server? $page = Page.new end component_paths = ComponentPaths.new(app_path) component_paths.require_in_components component_paths end |
.defaults ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/volt/config.rb', line 7 def defaults app_name = File.basename(Dir.pwd) { app_name: app_name, db_name: ENV['DB_NAME'] || (app_name + '_' + Volt.env.to_s), db_host: ENV['DB_HOST'] || 'localhost', db_port: (ENV['DB_PORT'] || 27_017).to_i, db_driver: ENV['DB_DRIVER'] || 'mongo', } end |
.env ⇒ Object
37 38 39 |
# File 'lib/volt.rb', line 37 def env @env ||= Volt::Environment.new end |
.reset_config! ⇒ Object
Resets the configuration to the default (empty hash)
19 20 21 22 23 |
# File 'lib/volt/config.rb', line 19 def reset_config! self.configure do |c| c.from_h(defaults) end end |
.run_files_in_config_folder ⇒ Object
Load in all .rb files in the config folder
26 27 28 29 30 |
# File 'lib/volt/config.rb', line 26 def run_files_in_config_folder Dir[Dir.pwd + '/config/*.rb'].each do |config_file| require(config_file) end end |
.spec_setup(app_path = '.') ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/volt/spec/setup.rb', line 2 def self.spec_setup(app_path = '.') if RUBY_PLATFORM == 'opal' require 'volt' else ENV['SERVER'] = 'true' if ENV['BROWSER'] require 'capybara' require 'capybara/dsl' require 'capybara/rspec' require 'capybara/poltergeist' end require 'volt' require 'volt/boot' # Require in app Volt.boot(Dir.pwd) if ENV['BROWSER'] require 'volt/server' .server do |app, port| require 'rack/handler/thin' Rack::Handler::Thin.run(app, Port: port) end .app = Server.new(app_path).app if ENV['BROWSER'] == 'phantom' .default_driver = :poltergeist elsif ENV['BROWSER'] == 'chrome' .register_driver :chrome do |app| ::Selenium::Driver.new(app, browser: :chrome) end .default_driver = :chrome elsif ENV['BROWSER'] == 'firefox' # require 'selenium/webdriver' # # require 'selenium/client' # .default_driver = :selenium # Capybara.register_driver :selenium_firefox do |app| # Capybara::Selenium::Driver.new(app, :browser => :firefox) # end # Capybara.current_driver = :selenium_firefox elsif ENV['BROWSER'] == 'safari' # Needs extension .register_driver :safari do |app| ::Selenium::Driver.new(app, browser: :safari) end .default_driver = :safari end end end end |
.user ⇒ Object
Return the current user.
87 88 89 90 91 92 93 94 |
# File 'lib/volt.rb', line 87 def user user_id = self.user_id if user_id return $page.store._users.find_one(_id: user_id) else return nil end end |
.user_id ⇒ Object
Get the user_id from the cookie
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/volt.rb', line 52 def user_id if Volt.client? user_id_signature = $page.._user_id else # Check meta for the user id and validate it = Thread.current['meta'] if user_id_signature = ['user_id'] else user_id_signature = nil end end if user_id_signature.nil? return nil else index = user_id_signature.index(':') user_id = user_id_signature[0...index] if RUBY_PLATFORM != 'opal' hash = user_id_signature[(index+1)..-1] # Make sure the user hash matches if BCrypt::Password.new(hash) != "#{Volt.config.app_secret}::#{user._id}" # user id has been tampered with, reject raise "user id or hash has been tampered with" end end return user_id end end |