How to set UIScrollView constraints for expanding height using FluentLayout? - xamarin.ios

I'm trying to create a ViewController in Xamarin.iOS to show a modal page that scales height as needed, and when not enough height is available it will scroll the content.
Anyone suggestions how to set the UIScrollView to do this?
Currently I can show
a height scaled View that is Y centered (showSmallDesign = true)
and I can show a View that uses max height that can scroll (showSmallDesign = false)
But I can’t combine those two behaviours for some reason; creating a scroll view that expands height until parent height and enabling the scroll. I have tried a lot of different constraints but it wont work.
This is my UIController (copy paste and it should work)
public class DialogViewModelBaseController : UIViewController
{
private readonly bool showSmallDesign = false;
public override void ViewDidLoad()
{
///
/// Create Views
///
var brownOuterView = new UIView {BackgroundColor = UIColor.Brown};
brownOuterView.Layer.CornerRadius = 20;
View.Add(brownOuterView);
var greenScrollView = showSmallDesign
? new UIView { BackgroundColor = UIColor.Green }
: new UIScrollView() { BackgroundColor = UIColor.Green };
brownOuterView.Add(greenScrollView);
var cyanInnerView = new UIView {BackgroundColor = UIColor.Cyan};
greenScrollView.Add(cyanInnerView);
var redLabel = new UILabel
{
LineBreakMode = UILineBreakMode.WordWrap,
Lines = 0,
BackgroundColor = UIColor.Red
};
redLabel.Text = showSmallDesign
? "Lorem ipsum"
: "Lorem ipsum dolor sit amet consectetur adipiscing elit. Aenean id lorem at tellus euismod gravida. Morbi scelerisque molestie nulla, pulvinar congue neque viverra ac. Donec euismod bibendum lectus eget ultrices. Ut eu vehicula lectus. In est orci, feugiat a sollicitudin eu, posuere ac sem. Quisque eu egestas lectus. Aliquam rhoncus dictum nisl a ullamcorper. Donec eget fermentum purus. Proin accumsan aliquam lacus ut convallis. Etiam tincidunt vitae nunc non sodales. Cras vitae nunc mattis, ultricies turpis et, laoreet nulla. Duis blandit sit amet libero ac cursus. Praesent ultricies erat laoreet turpis placerat scelerisque. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean id lorem at tellus euismod gravida. Morbi scelerisque molestie nulla, pulvinar congue neque viverra ac. Donec euismod bibendum lectus eget ultrices. Ut eu vehicula lectus. In est orci, feugiat a sollicitudin eu, posuere ac sem. Quisque eu egestas lectus. Aliquam rhoncus dictum nisl a ullamcorper. Donec eget fermentum purus. Proin accumsan aliquam lacus ut convallis. Etiam tincidunt vitae nunc non sodales. Cras vitae nunc mattis, ultricies turpis et, laoreet nulla. Duis blandit sit amet libero ac cursus. Praesent ultricies erat laoreet turpis placerat scelerisque. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean id lorem at tellus euismod gravida. Morbi scelerisque molestie nulla, pulvinar congue neque viverra ac. Donec euismod bibendum lectus eget ultrices. Ut eu vehicula lectus. In est orci, feugiat a sollicitudin eu, posuere ac sem. Quisque eu egestas lectus. Aliquam rhoncus dictum nisl a ullamcorper. Donec eget fermentum purus. Proin accumsan aliquam lacus ut convallis. Etiam tincidunt vitae nunc non sodales. Cras vitae nunc mattis, ultricies turpis et, laoreet nulla. Duis blandit sit amet libero ac cursus. Praesent ultricies erat laoreet turpis placerat scelerisque. XXXX";
cyanInnerView.Add(redLabel);
var blueButton = new UIButton {BackgroundColor = UIColor.Blue};
blueButton.SetTitle(" OK ", UIControlState.Normal);
blueButton.TouchUpInside += (sender, args) =>
{
DismissViewController(true, null);
};
cyanInnerView.Add(blueButton);
var outerMargin = 10;
var innerMargin = 16;
///
/// Layout Views
///
View.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints();
View.AddConstraints(
brownOuterView.AtRightOfSafeArea(View, outerMargin),
brownOuterView.AtLeftOfSafeArea(View, outerMargin)
);
if (showSmallDesign)
{
View.AddConstraints(
// works for none scroll subview (small resizable height)
brownOuterView.WithSameCenterY(View),
brownOuterView.Height().LessThanOrEqualTo().HeightOf(View.SafeAreaLayoutGuide).Minus(2 * outerMargin) // this resizes height to max View size
);
}
else
{
View.AddConstraints(
// works for scroll subview (maximum height)
brownOuterView.AtTopOfSafeArea(View, outerMargin),
brownOuterView.AtBottomOfSafeArea(View, outerMargin)
);
}
brownOuterView.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints();
brownOuterView.AddConstraints(
greenScrollView.AtRightOf(brownOuterView, outerMargin),
greenScrollView.AtLeftOf(brownOuterView, outerMargin),
greenScrollView.AtTopOf(brownOuterView, outerMargin),
greenScrollView.AtBottomOf(brownOuterView, outerMargin)
);
greenScrollView.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints();
greenScrollView.AddConstraints(
cyanInnerView.AtTopOf(greenScrollView, innerMargin),
cyanInnerView.AtLeftOf(greenScrollView, innerMargin),
cyanInnerView.Width().EqualTo().WidthOf(greenScrollView).Minus(2 * innerMargin),
cyanInnerView.Bottom().EqualTo().BottomOf(greenScrollView).Minus((nfloat)(innerMargin)) // constraint on last item to let scroll work
);
cyanInnerView.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints();
cyanInnerView.AddConstraints(
redLabel.WithSameWidth(cyanInnerView),
redLabel.AtTopOf(cyanInnerView),
blueButton.Below(redLabel, 20),
blueButton.Bottom().EqualTo().BottomOf(cyanInnerView).Minus((nfloat)(20)) // constraint on last item to let scroll work
);
}
}
To show the Controller as Modal, just use something like:
var dialogVC = new DialogViewModelBaseController()
{
ModalPresentationStyle = (DeviceInfo.IsPhone) ? UIModalPresentationStyle.OverCurrentContext : UIModalPresentationStyle.FormSheet,
ModalTransitionStyle = UIModalTransitionStyle.CoverVertical
};
var vc = CrossCurrentViewController.GetTopViewController();
vc.PresentViewController(dialogVC, true, null);

I found a solution, a modal page that stretches for all content and when max screensize has been reached it will scroll.
The trick was resetting the HeightConstraint after 'ViewDidLayoutSubviews', because the child views then measured their height.
And to catch device rotations I also reset the height after 'UIDeviceOrientationDidChangeNotification'.
Here it is, free to use:
public class DialogViewModelBaseController : UIViewController
{
private readonly nfloat minimumHeight = 100;
private readonly UIColor backgroundColor = UIColor.White;
private readonly Margins outerMargin = new Margins(10, 10, 10, 10);
private readonly Margins innerMargin = new Margins(16, 16, 16, 16);
private UIView outerShellView;
private UIView contentView;
private FluentLayout viewHeightContraint;
private NSObject deviceRotateNotificationToken;
public override void ViewWillAppear(bool animated)
{
base.ViewWillAppear(animated);
View.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints();
deviceRotateNotificationToken = Foundation.NSNotificationCenter.DefaultCenter
.AddObserver(new NSString("UIDeviceOrientationDidChangeNotification"), OnDeviceRotated);
}
public override void ViewWillDisappear(bool animated)
{
base.ViewWillDisappear(animated);
deviceRotateNotificationToken?.Dispose();
}
public override void ViewDidLoad()
{
///
/// Create Views
///
View.BackgroundColor = UIColor.Clear;
outerShellView = new UIView { BackgroundColor = backgroundColor };
outerShellView.Layer.CornerRadius = 20;
outerShellView.ClipsToBounds = true;
View.Add(outerShellView);
var greenScrollView = new UIScrollView();
outerShellView.Add(greenScrollView);
contentView = new UIView();
greenScrollView.Add(contentView);
var redLabel = new UILabel
{
LineBreakMode = UILineBreakMode.WordWrap,
Lines = 0
};
//redLabel.Text ="Lorem ipsum dolor sit amet";
redLabel.Text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vitae rutrum nulla. Etiam ultricies suscipit augue, non molestie lorem pellentesque sed. Vestibulum viverra pellentesque pharetra. Vivamus ut tincidunt lectus, eu maximus purus. Sed malesuada dignissim augue, sodales finibus ligula molestie at. Duis vitae felis vitae quam luctus pretium. Phasellus pulvinar ligula sit amet arcu porttitor facilisis. Vivamus a pellentesque urna. Sed elit elit, cursus vitae pharetra at, rutrum et lectus. Vivamus at dignissim lacus. Fusce viverra ultricies velit eu pretium. Donec tincidunt lacinia eros, nec accumsan libero viverra sed. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vitae rutrum nulla. Etiam ultricies suscipit augue, non molestie lorem pellentesque sed. Vestibulum viverra pellentesque pharetra. Vivamus ut tincidunt lectus, eu maximus purus. Sed malesuada dignissim augue, sodales finibus ligula molestie at. Duis vitae felis vitae quam luctus pretium. Phasellus pulvinar ligula sit amet arcu porttitor facilisis. Vivamus a pellentesque urna. Sed elit elit, cursus vitae pharetra at, rutrum et lectus. Vivamus at dignissim lacus. Fusce viverra ultricies velit eu pretium. Donec tincidunt lacinia eros, nec accumsan libero viverra sed. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vitae rutrum nulla. Etiam ultricies suscipit augue, non molestie lorem pellentesque sed. Vestibulum viverra pellentesque pharetra. Vivamus ut tincidunt lectus, eu maximus purus. Sed malesuada dignissim augue, sodales finibus ligula molestie at. Duis vitae felis vitae quam luctus pretium. Phasellus pulvinar ligula sit amet arcu porttitor facilisis. Vivamus a pellentesque urna. Sed elit elit, cursus vitae pharetra at, rutrum et lectus. Vivamus at dignissim lacus. Fusce viverra ultricies velit eu pretium. Donec tincidunt lacinia eros, nec accumsan libero viverra sed XXXX";
contentView.Add(redLabel);
var blueButton = new UIButton { BackgroundColor = UIColor.Gray };
blueButton.SetTitle(" Close ", UIControlState.Normal);
blueButton.TouchUpInside += (sender, args) =>
{
DismissViewController(true, null);
};
contentView.Add(blueButton);
///
/// Layout Views
///
View.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints();
viewHeightContraint = outerShellView.Height().EqualTo(minimumHeight);
View.AddConstraints(
outerShellView.AtRightOfSafeArea(View, outerMargin.Right),
outerShellView.AtLeftOfSafeArea(View, outerMargin.Left),
outerShellView.WithSameCenterY(View),
viewHeightContraint
);
outerShellView.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints();
outerShellView.AddConstraints(
greenScrollView.AtRightOf(outerShellView),
greenScrollView.AtLeftOf(outerShellView),
greenScrollView.AtTopOf(outerShellView),
greenScrollView.AtBottomOf(outerShellView)
);
greenScrollView.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints();
greenScrollView.AddConstraints(
contentView.AtTopOf(greenScrollView, innerMargin.Top),
contentView.AtLeftOf(greenScrollView, innerMargin.Left),
contentView.Width().EqualTo().WidthOf(greenScrollView).Minus(innerMargin.Left + innerMargin.Right),
contentView.Bottom().EqualTo().BottomOf(greenScrollView)//.Minus(innerMargin.Bottom) // constraint on last item to let scroll work
);
contentView.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints();
contentView.AddConstraints(
redLabel.WithSameWidth(contentView),
redLabel.AtTopOf(contentView),
blueButton.Below(redLabel, 20),
blueButton.Bottom().EqualTo().BottomOf(contentView) // constraint on last item to let scroll work
);
}
public override void ViewDidLayoutSubviews()
{
base.ViewDidLayoutSubviews();
SetViewHeight();
}
void OnDeviceRotated(NSNotification notification)
{
// Make sure View is resized after rotation, during ViewDidLayoutSubviews SubViews height probably isn't adjusted yet
SetViewHeight();
}
private void SetViewHeight()
{
var contentHeight = contentView.Frame.Size.Height;
if (contentHeight <= 0)
{
return;
}
var safeAreaHeight = View.SafeAreaLayoutGuide.LayoutFrame.Height;
var contentHeightWithMargins = contentHeight
+ outerMargin.Top + outerMargin.Bottom
+ innerMargin.Top + innerMargin.Bottom;
if (contentHeightWithMargins > safeAreaHeight)
{
contentHeightWithMargins = safeAreaHeight;
}
if (contentHeightWithMargins < minimumHeight)
{
contentHeightWithMargins = minimumHeight;
}
if (viewHeightContraint.Constant == contentHeightWithMargins)
{
return;
}
View.RemoveConstraints(viewHeightContraint);
viewHeightContraint = outerShellView.Height().EqualTo(contentHeightWithMargins);
View.AddConstraints(viewHeightContraint);
}
}
TIP: just put everything in 'contentView' and don't forget to set constraint of last item in contentView to the bottom of the contentView.

Related

how to convert a text file into google doc using google docs api

I have the output of OCRed files that I need to convert into a Google Doc. The best closest use case I have seen is the codelab to convert speech into a Google Doc. However I cannot figure out if those calls exist in the node.js libs, and if not how to get this done. Some guidance on how to use the batchUpdate to create a bunch of requests along with paragraphs/line breaks would be nice, and specifically how to do this index calculation.
Based on your comment I will assume that your goal is to translate a TXT file to a Doc. If my assumption is correct, then you can upload the TXT document easily by following these steps. First of all you should make a documents.create request in order to create the Doc itself. Read its response, because you will need the field revisionId later. Then you only need to send a documents.batchUpdate request like this example:
{
"requests": [
{
"insertText": {
"location": {
"index": 1
},
"text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent nec erat eget nisl facilisis luctus vitae ac lorem. Quisque lobortis iaculis massa, in mattis lorem eleifend eu. Vivamus ac placerat nisi. Vivamus odio nulla, faucibus ac lobortis vel, sodales vel velit. Nam quam ex, posuere in risus quis, pretium euismod lectus. Donec accumsan varius tellus, vitae suscipit ipsum scelerisque sit amet. Vestibulum ut dapibus enim. Nam et eros gravida, vulputate libero eu, pellentesque odio. Sed tempus ante non metus imperdiet varius. Phasellus ut lacus sapien. Suspendisse vestibulum eleifend felis finibus sollicitudin. Nam quis vehicula lectus, in convallis eros. \nEtiam vel erat id dui commodo faucibus. Pellentesque ac lacinia libero. Nunc blandit elementum nunc, at mattis eros tincidunt ac. Duis vitae scelerisque nisl, venenatis venenatis purus. Fusce felis lacus, blandit ac quam vitae, vulputate vestibulum felis. Morbi aliquam mauris metus, eget venenatis orci pretium eu. Nam cursus eget dolor ut tempor. \nSed turpis dolor, finibus pharetra elit sed, pulvinar semper nisi. Quisque sed iaculis purus. Quisque aliquet feugiat augue vel feugiat. Mauris in est vel elit aliquet luctus cursus quis nibh. Nam condimentum velit felis, vitae hendrerit lacus imperdiet non. Nam luctus quam et tortor tempus luctus. Aenean aliquam nibh vel varius scelerisque. Sed sit amet tortor lacus. Curabitur ullamcorper, justo non vulputate dapibus, lorem ex ultrices arcu, non efficitur nulla nisl vitae ante. Ut quis sem sit amet mi ultrices pulvinar quis nec nunc. \nEtiam bibendum neque nec dui finibus blandit. Proin tincidunt purus id ante interdum, eget convallis sem dictum. Proin quis justo vitae ligula sagittis rhoncus. Nulla at arcu et orci iaculis ornare. Maecenas eget neque maximus, dignissim urna eu, efficitur turpis. Aenean tempor elit sed eleifend luctus. Suspendisse in auctor sapien. Nunc condimentum libero in lacus ornare gravida. Curabitur id felis nunc. Fusce sed pellentesque nunc. Morbi ligula odio, ornare hendrerit arcu id, dignissim mollis turpis. \nAliquam est dolor, consectetur ac imperdiet vel, imperdiet id dolor. Praesent ut pellentesque felis. Cras eget dictum nunc. Vestibulum nec nulla ut ipsum vestibulum scelerisque. Vivamus quis lorem sem. Cras vitae finibus dolor. Vivamus et nibh orci. Vestibulum vel justo ullamcorper, dapibus neque quis, iaculis lectus. Donec sagittis, tellus at tincidunt varius, est augue suscipit magna, nec sagittis elit diam id libero. Nam est eros, maximus sed malesuada id, pulvinar eget nulla. Donec ullamcorper ligula vel massa aliquam, nec bibendum sem fringilla. Nunc vestibulum dignissim augue, vitae pretium risus mattis non. Etiam ante tortor, tincidunt vitae velit at, posuere congue nulla."
}
}
],
"writeControl": {
"targetRevisionId": "{YOUR TARGET REVISION ID}"
}
}
I used a lorem ipsum text as a model. Please keep in mind that pagebreaks are depicted with the \n glyph. Update the text field with your desired text and write the targetRevisionId from the previous step into the homonymous field. At this point the Doc should be updated with your goal text.

Adding a delimiter in front of a regex match in python

I have the following text chunk here and would like to add a delimiter in front of the clause number (4.1 ... 4.2 ..., etcetera)
4.1 Use unique passwords (Manual)
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent eu velit a libero convallis hendrerit. Nulla interdum fermentum viverra. Maecenas tincidunt sollicitudin odio. Aenean a erat sagittis, lacinia nulla eu, ornare velit. Suspendisse tempor at nisi eu mattis. Phasellus in ante magna. Quisque nisl lacus, fermentum pulvinar odio id, auctor sagittis nisl. Proin bibendum cursus orci vitae finibus.
4.2 Set password lifetime (Automated)
Quisque ut vehicula diam. Maecenas ac nulla cursus, dictum odio ac, lobortis dui. Nullam euismod, enim sed mollis elementum, tellus urna porttitor augue, ac venenatis tortor diam eget leo. In euismod dapibus tortor et vehicula. Aliquam erat volutpat. Quisque id rutrum libero. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nullam sollicitudin pellentesque magna sit amet malesuada. Aenean pulvinar metus sed justo tincidunt, et fermentum sem gravida. Aliquam varius lacus sit amet aliquam elementum. Pellentesque a varius magna, at euismod ligula. Praesent odio nunc, faucibus vel urna non, varius porta velit.
Such that the 'delimiter' would be present for every clause in the text:
'delimiter' 4.3 Set password expiry warning (Automated)
Quisque ut vehicula diam. Maecenas ac nulla cursus, dictum odio ac, lobortis dui. Nullam euismod, enim sed mollis elementum, tellus urna porttitor augue, ac venenatis tortor diam eget leo. In euismod dapibus tortor et vehicula. Aliquam erat volutpat. Quisque id rutrum libero. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.
I am using re.sub to perform matching and replacement but I am not too sure how to do without removing the clause number entirely:
result = re.sub(r'[0-9\.]{3,}\s*[A-Z][\d\w\s/\-\,\(\)\\\"]{1,}\s*\(Automated|Manual\)', 'delimiter', text)
Any help would be appreciated!
You might use
^\d+(?:\.\d+)? .*\((?:Manual|Automated)\)
^ Start of string
\d+(?:\.\d+)? Match 1+ digits with an optional decimal part
.*\((?:Manual|Automated)\) Match a space and either (Manual) or (Automated) in the string
Regex demo
In the replacement, use the delimiter followed by the full match
delimiter \g<0>
For example
import re
regex = r"^\d+(?:\.\d+)? .*\((?:Manual|Automated)\)"
s = ("4.1 Use unique passwords (Manual)\n"
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent eu velit a libero convallis hendrerit. Nulla interdum fermentum viverra. Maecenas tincidunt sollicitudin odio. Aenean a erat sagittis, lacinia nulla eu, ornare velit. Suspendisse tempor at nisi eu mattis. Phasellus in ante magna. Quisque nisl lacus, fermentum pulvinar odio id, auctor sagittis nisl. Proin bibendum cursus orci vitae finibus.")
result = re.sub(regex, r"delimiter \g<0>", s, 0, re.MULTILINE)
if result:
print (result)
Output
delimiter 4.1 Use unique passwords (Manual) Lorem ipsum dolor sit
amet, consectetur adipiscing elit. Praesent eu velit a libero
convallis hendrerit. Nulla interdum fermentum viverra. Maecenas
tincidunt sollicitudin odio. Aenean a erat sagittis, lacinia nulla eu,
ornare velit. Suspendisse tempor at nisi eu mattis. Phasellus in ante
magna. Quisque nisl lacus, fermentum pulvinar odio id, auctor sagittis
nisl. Proin bibendum cursus orci vitae finibus.

showing error of "cannot read property substring of undefined "

this is a daily blog project in which i can publish a new blog on pushing a button,but when i pushed the button instead of redirecting me to home page with newly added blog the browser isshowing this error shown in screenshot,that is "cannot read property substring of undefined".
//app.js code
const express=require("express");
const bodyParser=require("body-parser");
const _=require("lodash");
const ejs=require("ejs");
const homeStartingContent = "Lacus vel facilisis volutpat est velit egestas dui id ornare. Semper auctor neque vitae tempus quam. Sit amet cursus sit amet dictum sit amet justo. Viverra tellus in hac habitasse. Imperdiet proin fermentum leo vel orci porta. Donec ultrices tincidunt arcu non sodales neque sodales ut. Mattis molestie a iaculis at erat pellentesque adipiscing. Magnis dis parturient montes nascetur ridiculus mus mauris vitae ultricies. Adipiscing elit ut aliquam purus sit amet luctus venenatis lectus. Ultrices vitae auctor eu augue ut lectus arcu bibendum at. Odio euismod lacinia at quis risus sed vulputate odio ut. Cursus mattis molestie a iaculis at erat pellentesque adipiscing.";
const aboutContent = "Hac habitasse platea dictumst vestibulum rhoncus est pellentesque. Dictumst vestibulum rhoncus est pellentesque elit ullamcorper. Non diam phasellus vestibulum lorem sed. Platea dictumst quisque sagittis purus sit. Egestas sed sed risus pretium quam vulputate dignissim suspendisse. Mauris in aliquam sem fringilla. Semper risus in hendrerit gravida rutrum quisque non tellus orci. Amet massa vitae tortor condimentum lacinia quis vel eros. Enim ut tellus elementum sagittis vitae. Mauris ultrices eros in cursus turpis massa tincidunt dui.";
const contactContent = "Scelerisque eleifend donec pretium vulputate sapien. Rhoncus urna neque viverra justo nec ultrices. Arcu dui vivamus arcu felis bibendum. Consectetur adipiscing elit duis tristique. Risus viverra adipiscing at in tellus integer feugiat. Sapien nec sagittis aliquam malesuada bibendum arcu vitae. Consequat interdum varius sit amet mattis. Iaculis nunc sed augue lacus. Interdum posuere lorem ipsum dolor sit amet consectetur adipiscing elit. Pulvinar elementum integer enim neque. Ultrices gravida dictum fusce ut placerat orci nulla. Mauris in aliquam sem fringilla ut morbi tincidunt. Tortor posuere ac ut consequat semper viverra nam libero.";
const app=express();
const posts=[];
app.set('view engine','ejs');
app.use(bodyParser.urlencoded({extended:true}));
app.use(express.static("public"));
app.get("/",function(req,res){
res.render("home",{startingContent:homeStartingContent,newPost:posts});
});
app.get("/contact",function(req,res){
res.render("contact",{contactcontent:contactContent});
});
app.get("/about",function(req,res){
res.render("about",{aboutcontent:aboutContent});
});
app.get("/compose",function(req,res){
res.render("compose")
});
app.post("/compose",function(req,res){
const newPost={
title:req.body.postTitle,
content:req.body.postContent
}
posts.push(newPost);
res.redirect("/");
});
//routin parameters
app.get("/newPost/:postName",function(req,res){
const requestedTitle=_.lowerCase(req.params.postName);
posts.forEach(function(post){
const storedTitle=_.lowerCase(post.title);
if(storedTitle===requestedTitle){
res.render("post",{
title:post.title,
content:post.content
});
};
});
});
app.listen(3000,function(req,res){
console.log("server working on 3000");
});
//EJS template from where error is coming
<%- include('partials/header') -%>
<h1>Home</h1>
<p><%=startingContent%></p>
<%newPost.forEach(function(newBlog){%>
<h1><%=newBlog.title%></h1>
<p><%=newBlog.content.substring(0,100) +"..."%>
Read more
</p>
<%})%>
<%- include('partials/footer')-%>
enter image description here

p:scrollpanel not working inside a p:notification bar

I need to apply scroll panel inside a notification bar of prime faces, content is visible but scroll is not working.
Can anyone help me?
The code is given below have a look. Thanks.
<p:notificationBar position="top" effect="slide" style="margin-left:30px;width:500px;margin-top:51px;height:300px" styleClass="top" widgetVar="bar">
<p:scrollPanel style="width:400px;height:280px">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean blandit tortor a ipsum vehicula, in semper sapien auctor. Nulla tempor eget est non consequat. Nulla sit amet lorem justo. Cras non tellus eros. Sed ultricies orci ut quam interdum fringilla. Nam vitae massa ac mi elementum mattis vel vitae sem. Ut eros ipsum, scelerisque a erat a, eleifend luctus nibh. Interdum et malesuada fames ac ante ipsum primis in faucibus.
</p>
<p>
Vivamus ac ullamcorper magna. Aenean felis ante, elementum sit amet urna at, eleifend aliquet velit. Morbi a convallis magna. In nec leo vel dolor hendrerit pharetra. Cras in iaculis enim. Aenean porta sapien dignissim turpis dapibus, eu dictum velit elementum. Aliquam sollicitudin gravida luctus.
</p>
<p>
Ut vel nulla sit amet erat laoreet eleifend nec sed lacus. Quisque placerat diam vitae justo eleifend, rutrum mollis mauris fringilla. Curabitur turpis odio, euismod id lorem a, ultricies suscipit ligula. Pellentesque ut erat a leo rhoncus porta ac sed velit. Nunc at erat ligula. Fusce vehicula posuere interdum. Curabitur tempus, tortor at sollicitudin dapibus, erat ante varius nisl, id dictum erat ipsum porttitor ipsum. Interdum et malesuada fames ac ante ipsum primis in faucibus. Nulla id varius enim, sed rutrum orci.
</p>
</p:scrollPanel>
</p:notificationBar>
Set the mode attribute value to native of the <p:scrollPanel>:
<p:scrollPanel mode="native"...>
Unfortunately I don't know what it is mean and what the other enabled values. But when I set it to this value the scrollPanel got working in this component.

Vim: select until first match

Lorem ipsum dolor sit amet, hello consectetur adipiscing elit. Vivamus lorem mauris, dictum in ornare sit amet, vulputate at nibh. Integer volutpat justo vitae enim ultrices ultrices. In quis tortor id diam tincidunt feugiat at ut odio. Donec faucibus sapien vitae ante aliquam malesuada. Nam facilisis, metus in tincidunt posuere, hello massa nisi vulputate nunc, id rutrum mi enim non risus. Phasellus ac nisl non tortor pulvinar accumsan at eget leo. Nunc neque mauris, vehicula eget malesuada a, vestibulum non urna. Proin iaculis sem vel nulla porta tristique. Donec magna diam, eleifend quis vehicula in, aliquam in dolor. In et tellus nec metus volutpat dapibus. Duis hello purus dolor, aliquet in vehicula id, adipiscing id lorem. Vivamus elementum, mauris non vulputate tempus, risus elit tincidunt nunc, et posuere velit ligula sit amet purus. Integer pellentesque ultrices sodales. Donec in arcu eu est ullamcorper tincidunt placerat at sem.
I want select everything from the beginning until first occur of hello
I try this
/^.*hello
But it returns whole text until the last hello.
So how to do it?
You can use the visual mode and then search for hello to extend it
0v/hello<cr>
should do it
Otherwise to do a "non-greedy" search you can try {-}
/^.\{-\}hello
Just make the capture non-greedy:
/^.\{-}hello
This matches "as few as possible".

Resources