Comments (2)
Aha. Yeah, the “docs” need a ton of work. (I think of it as “I need to write docs!”. :)
The configuration system is actually really flexible and I think will let you do anything you want. It’s actually quite simple underneath: any configuration changes you make to any widget class — whether that’s Fortitude::Widget
(the base class), Fortitude::Widgets::Html5
(which inherits from Fortitude::Widget
), some common base class you define that all your widgets inherit from, or an individual view — apply to that class and all classes that inherit from it, period. (Unless, of course, a subclass itself has a different setting for that configuration option.) You can even create a module that uses ActiveSupport::Concern
and included do … end
to apply configuration changes when included, and that'll work fine, too.
So, in short, you can do it any way you want:
Option 1 — global, just like Erector:
Fortitude::Widget.class_eval do
doctype :html5
start_and_end_comments false
end
Every single widget in the entire Ruby process, unless it overrides these, will use a doctype
of :html5
, and will have start_and_end_comments
disabled.
Option 2 — your own base class:
class Views::Base < Fortitude::Widget
doctype :html5
start_and_end_comments false
end
If you now inherit all your widgets from Views::Base
, they'll all inherit these settings, but if you included other code (yours, or someone else's) that inherited from Fortitude::Widget
through a different path, your configuration settings wouldn't affect their widgets, by default. (Of course, you can just send the appropriate doctype
or start_and_end_comments
messages to their class, and it'll change that configuration, too.)
And, of course, there are plenty of other possibilities. Personally, I would recommend that people use option #2 — define your own widget base class (of any name you desire at all), and inherit from that. I like it because it encapsulates your configuration settings, if for some reason there are other, unrelated Fortitude widgets that get used in your system for something different; and I like it because it gives you a convenient place to override behavior, include or define global “helper” methods (using Erector/Fortitude-style helpers — i.e., just methods/modules/etc., rather than the completely-different-style Rails helpers), and so on.
But it’s really completely up to you. If you don’t like making a Views::Base
class, feel free to subclass Fortitude::Widget
everywhere and just apply configuration changes to it directly (with the one caveat that there isn’t a great place to include helpers — you can definitely do it on Fortitude::Widget
directly and it will work fine, but it’s, yeah, a bit messy).
The only things I wouldn’t necessarily recommend are inheriting from Fortitude::Widgets::Html5
— it’ll work fine, but these “doctype-specific” widgets are really just intended as quick little helpers for one-offs, not things you should necessarily build significant systems on. And I wouldn’t recommend defining a Fortitude::MyWidget
, just because that's in Fortitude's own namespace and hence could potentially conflict with something in the future.
Does that help you out?
from fortitude.
Yup, thanks for this! I'm pretty sure that once you respond to enough issues, it'll just be a matter of aggregating all of these fine answers and you'll have your docs written!
from fortitude.
Related Issues (20)
- Unit testing of widgets without loading entire Rails stack in test environment? HOT 2
- Script to convert to and from HTML/ERb? HOT 3
- :csrf_meta_tags helper unavailable? HOT 1
- Even more forms weirdness, or... HOT 11
- Using #inline_html with a Rails view context HOT 2
- Implicit passing of `needs` variables fails when View class is named the same as the `needs` key HOT 4
- Can't mark HTML attribute values as html_safe HOT 1
- Upgraded to Rails 4.2.5.2 and everything is blowing up HOT 3
- use controller.view_paths to resolve view paths when calculating widget_class_from_file HOT 1
- Status? HOT 8
- alias_method_chain deprecated in Rails 5 HOT 2
- fix Travis build HOT 2
- Release latest code to rubygems HOT 1
- ArgumentError: wrong number of arguments (given 5, expected 4) with ActionView 4.2.6 HOT 2
- Issues when running tests: "uninitialized constant OopRailsServer::RailsServer::Bundler" HOT 1
- Regression: automatic inclusion of Rails helpers breaks implicit route arguments HOT 6
- Fortitude prevents Rails csrf_meta_tags from being rendered in the <head> element HOT 1
- retina_images repo unavailable
- Single arity template handlers are deprecated in Rails 6.0
- Still maintained? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fortitude.