How can i prevent roo console from regenerating the thymeleaf views? (ROO2 RC1) - thymeleaf

Maybe it's because i'm approaching the thymeleaf views in a wrong way but i couldn't find the best way to do it yet.
I have my roo generated project with their thymeleaf views, i needed to delete some fields from the form, lock some other and many more little changes like css and js.
My problem is that everytime i open the roo console, it overwrite all my editions and leaves the views as they come by default. There is some way to exclude my edited views from regenerating? or is there some better way to edit the views?
Thanks.

To prevent that Spring Roo removes your changes including the default items you sould include the data-z="user-managed" attribute in that items you want to maintain.
Remember that the data-z="user-managed" attribute is only available in that elements that have id attribute.
Of course, if you are going to change a big number of fields or you're going to change the HTML structure of an specific form, you should include the data-z="user-managed" in the <body> element.
After that, if you open the Spring Roo shell, any change will be applied.
Hope it helps,

Related

How to customize HTML structure in ActiveAdmin layout?

I am trying to change the structure and design of the components of the ActiveAdmin layout, such as the navbar menu, icons and customize it to my style. Is this possible?
I need to overwrite the source code to be able to change the HTML structure, but I have tried to do it by placing files in the / lib folder and I have not succeeded. How could I overwrite the ActiveAdmin source code within my Rails project?
It is possible but many developers have discovered it is not easy. If you look through the various plugins you will find examples like Custom Layout, Sidebar, Menu and SubNav that may inspire you. However, if you are new to ActiveAdmin and your first priority is to customize the layout heavily then consider Administrate or vanilla Rails instead: they are still difficult, but you will be fighting the framework less.

Overriding the default views in RailsAdmin

I am using Ruby on Rails 4.2.1 with RailsAdmin. The gem works excellent, but I have the requirement that the layout of the admin panel and the forms must look different than what is generated by default. For example, the navigation should be horizontal top, the forms should order the fields in two columns.
So far I haven't find a way to copy the views locally and modify them (like in Devise for example). I have tried to replicate the views manually in the respective path under my views folder by copying the original views, but I got problems with the helper methods that are part of RailsAdmin not being accessible from my views.
I dug deeper and found that there is a task copy_views, it was referred to in questions for the older versions of the gem, but if I try to use it now rake rails_admin:copy_views, it is not available anymore.
Am I doing something wrong, or is there another way to do this?
You can create folders in your app
app/views/rails_admin/main for https://github.com/sferik/rails_admin/tree/master/app/views/rails_admin/main
app/views/layouts/rails_admin/ for
https://github.com/sferik/rails_admin/tree/master/app/views/layouts/rails_admin
Put modified files there. It can get a little messy and you will need to update the files if the gem changes.

How to change styling on rails-generated outputs

I am using twitter bootstrap installed by copying bootstrap.min.css, etc. into the vendor/assets folder.
When using rails forms validations, error messages appear using default styling, not the bootstrap styling I would expect (e.g. the h2 tag is much smaller and in a different text, the unordered list uses different bullets, etc.) How do I get bootstrap to override the default styling that rails uses when generating error messages for forms? I'm guessing this has something to do with the asset pipeline, but didn't see anything about overriding rails-generated content in the rails guide.
Thanks!
Sounds like you used some scaffolding which generated a CSS sheet. Go into app/assets/stylesheets and delete the stylesheet named "scaffolds.scss" (or just delete the parts you don't want).
To track down where that styling is coming from, you should use your browsers development tools. Inspect the element and it should tell you where the styling is coming from.

Checking CSS within a rails controller or in plain ruby?

I need to take a database text field and parse it for
duplication and garbage
malice
whitelisted selectors
compress and output as a css file
Since there might be a rails way I'm unaware or something ready made I'm asking before I waste time trying to reinvent a wheel. My searching revealed nothing, mostly in rails seems aimed at view level, and css seems to be an unattended niche in this area (plenty of html though).
I'm aware of the sanitize gem (doesn't do css immediately, yet another thing I'd need to map out and code) and the built in rails stuff (not a lot of tutorial, aimed mostly at the view level). I need a gem, lib, module or something similar that I can work with in a controller or queue.
EDIT:
Without getting too deep into the specifics of the project: administrative users can add css for their portions of the site. As part of the flow I'm going to save the raw css and then process and save the processed css. The db stuff is archival mostly, the css file is output immediately. Because there is few places to add modified css and only admins have access to the css, it sort of works but I'm looking to make it more robust in the future where admins who may not be as conversant with the security needs or not as css aware can operate.
The most basic example is that it just a text field on an admin page. The admin cuts and pastes css there, submits, and the application turns it into a css file that gets included with the designated pages, which works because the current admins know the application, the css of the application, and what they can and cannot change. The goal is to make this more robust for future admins who might not be as savvy.
To simply sanitize CSS, you can use the SanitizeHelper built into Rails: http://api.rubyonrails.org/classes/ActionView/Helpers/SanitizeHelper.html#method-i-sanitize_css
Have you looked at Sass? It has all of the parsing logic built in, for a superset of CSS. You could add a feature (Sass support) and save yourself the need to parse/validate the CSS all in one go.
You can generate output CSS from Sass (or just plain CSS, since Sass [with the SCSS syntax] is a fully-backward-compatible superset of CSS) like this:
output_css = Sass::Engine.new(sass_content, :syntax => :scss).render
There are a bunch of options that you'll probably want to look into at http://sass-lang.com/
Another option is Less. The new Twitter Bootstrap framework uses Less, and Rails 3.1 uses Sass. The biggest difference is that the official Less parser/compiler is built in JavaScript, so you could actually validate and compile in the user's browser while they work and show them any errors before they save. Of course then you need to run a JavaScript engine (e.g. V8) in your Rails application if you want to use Less to validate the incoming CSS still.

let user modify css propertise from front end of rails app

i am creating a cms / portal that i want each user to change certain css properise ie colors, widths, backgrounds etc to customise there own version of my site.
What is the best way to do this ? i have looked into sass but not sure if this is possible from front end as the css would need to be recompiled each time etc ?
Any one done this or got any suggestions please help.
thanks
rick
You can use sass if you like, but it's possible to do this using plain CSS too. Use whichever you prefer. Sass doesn't need to be recompiled for each request, it can be either:
Pre-compiled at deploy time
Served from a controller and page-cached
If you want your users to edit only certain properties then you can use a standard MVC approach to serve your stylesheets with page caching:
Create a stylesheet model with the columns you want to have editable.
Provide your users a form to manage their stylesheet (there are some good jQuery plugins for color selectors, etc.)
Serve the stylesheets from a controller (e.g. routed to /users/1/stylesheet.css)
Cache the stylesheet output using caches_page so it gets served statically on future requests.
Let the user edit an .scss file.
Use codemirror for editing.
SASS/SCSS: http://sass-lang.com/
CodeMirror: http://codemirror.net/csstest.html

Resources